Hello All,

I am trying to learn C++ on my own, but I think I am having some problems with Code::Blocks. I am familiar with Java (I did some CS as an undergrad) and I feel that the C++ basics are pretty easy to translate from Java; however, I am having problems with my compiler and it has been quite frustrating. My problem is as follows: I am using the Accelerated C++ book to learn since I am already familiar with OOP. I did a program from one of their chapters that uses header files (it's a gradebook code). The compiler keeps giving me "undefined reference to" errors (e.g. "undefined reference to 'read(std::istream&, Student_info&)' and the exact compiler error is listed at the end of this post) when I compile. I define the function read in the *.c file and I've done everything like the book says (looking for any misspelled word, etc). I can include the code if needed, but I thought I would see if it was something simple that I had forgotten (the code is a little lengthy). Also, all the files are in the same directory. Any help would be much appreciated. I attached the code to this message. Another problem, and I don't know if this is related, when I try to compile the *.cpp files one by one, I usually get a "C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\libmingw32.a(main.o):main.c:(.text+0x104)||undefined reference to `_WinMain@16'|" error. Thanks so much!

Allen

C:\Documents and Settings\Allen\My Documents\C++ Work\Grade_Project\gradeCalc.o:gradeCalc.cpp:(.text+0x210)||undefined reference to `read(std::istream&, Student_info&)'|
C:\Documents and Settings\Allen\My Documents\C++ Work\Grade_Project\gradeCalc.o:gradeCalc.cpp:(.text+0x28a)||undefined reference to `compare(Student_info const&, Student_info const&)'|
C:\Documents and Settings\Allen\My Documents\C++ Work\Grade_Project\gradeCalc.o:gradeCalc.cpp:(.text+0x414)||undefined reference to `grade(Student_info const&)'|
||=== Build finished: 3 errors, 0 warnings ===|

Dear fatalbert55,

Give me a reason why should I read the attached files. We are here to help somebody; not to provide a complete solution.

Please post the phrase of code where you got problems.

If you are compiling them one-by-one make sure you only compile and don't go to the linking process. I think you might be doing that and while trying to create an executable its not finding main. Read the compiler man pages and find the flag used to only compile and not link. Once everything is compiled you can link the object files together and create the executable.

commented: Seems about right to me. +36

Thanks Agni! That did the trick!

adatapost: I didn't include snippets of code because it wasn't a part of the code that was causing the problem. I was having problems with the compiler.

Thanks all for helping out the newb!

Allen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.