Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:22:12+00:00 2026-05-27T15:22:12+00:00

Assuming that if the error’s spotted in the .o file that it’s the linker’s

  • 0

Assuming that if the error’s spotted in the .o file that it’s the linker’s problem…

Anyway, I’m writing a program to organize the courses I want to take in college by outputting them into a nicely formatted HTML file. To do this, I’m going to throw a bunch of objects of my Course class into a list (the data structure I picked, unless someone warns otherwise), organize them by course code, and output them to the aforementioned HTML file, placing horizontal line breaks between each different major/minor/etc. At the top of each line-broken segment will be the name of the major, reading like;

AMS (Applied Mathematics and Statistics)

Whenever the user enters the course code (just the three letters, not the number), I want the class to check whether the code is on a .txt I provide with the program. Because if I’m going to have dozens of Courses in the end, why bloat my code with an fstream or a member function for each object? So I figured using some static magic might be a good idea. Then I get this error message, using g++;

(Sorry it looks messy, by the way, I’m not sure how to format this neatly here.)

In function `std::basic_ifstream >::open(char const*, std::_Ios_Openmode)’:

/usr/include/c++/4.5/fstream| 528 | undefined reference to Course::courses'
/usr/include/c++/4.5/fstream|533|undefined reference to
Course::courses’
/usr/include/c++/4.5/fstream|533|undefined reference to Course::courses'
obj/Debug/main.o In function
std::basic_filebuf >::is_open() const’:

/usr/include/c++/4.5/fstream|223|undefined reference to Course::courses'
obj/Debug/main.oIn function
std::basic_ifstream >::close()’:
/usr/include/c++/4.5/fstream|566|undefined reference to Course::courses'
obj/Debug/main.o:/usr/include/c++/4.5/fstream|529|more undefined references to
Course::courses’ follow

I’m then directed to this segment of the fstream header;

void open(const char* __s, ios_base::openmode __mode = ios_base::in)
  {
if (!_M_filebuf.open(__s, __mode | ios_base::in))
  this->setstate(ios_base::failbit);
else
  // _GLIBCXX_RESOLVE_LIB_DEFECTS
  // 409. Closing an fstream should clear error state
  this->clear();
  }

The two static members I have (open and close the stream, at the start and end of the whole collection process for the courses) as well as the member itself are declared like so;

class Course
{
    public:
        Course();
        void setup();
        bool confirm();
        stringstream entry;
        static void openCodeList() { courses.open("codes"); if (!courses.is_open()) exit(1); }
        static void closeCodeList() { courses.close(); }
    private:
        //Irrelevant strings and bits, etc, etc.
        static ifstream courses;
}

I do have other .cpp and .h files involved (namely a File class to handle actually outputting everything in the end), but I have not even mentioned these fstream-related members in any of them but my obviously WIP main.cpp;

int main()
{
    cout << "Welcome to the Stony Brook Course Organizer!  This program will help you\n"
            "organize the courses that you wish to take at Stony Brook University.\n\n";
    Course thefirst;
    Course::openCodeList();
    thefirst.setup();
    thefirst.confirm();
    Course::closeCodeList();
}

Any help in dealing with my static issues and advice for the future (even if not directly related to that) would greatly be appreciated. Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:22:13+00:00Added an answer on May 27, 2026 at 3:22 pm

    You need to define the static member in a source file of your program, outside of the class definition.

    E.g. in a .cpp:

    std::ifstream Course::courses;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming that writing nhibernate mapping files is not a big issue....or polluting your domain
Assuming that I want to use a hash as an ID instead of a
assuming that I know the PID of a process and want to do a
Assuming that I have a typedef declared in my .h file as such: typedef
I'm writing a gem that I want to extend a model. I tried defining
I'm currently writing a program, and couldn't figure out why I got an error
Assuming that I have a CronTriggerBean similar to <bean id=midMonthCronTrigger class=org.springframework.scheduling.quartz.CronTriggerBean> <property name=jobDetail ref=reminderJobDetail
Assuming that best practices have been followed when designing a new database, how does
Assuming that I know there is a git-daemon running at git://git.mycompany.com , how can
Assuming that one event has multiple handlers, if any of event handlers throw an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.