954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with compiler error for self-teacher

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 ===|

Attachments grade.cpp (0.57KB) grade.h (0.26KB) gradeCalc.cpp (1.64KB) median.cpp (0.63KB) median.h (0.14KB) Student_info.cpp (0.79KB) Student_info.h (0.44KB)
fatalbert55
Newbie Poster
2 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

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.

__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

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.

Agni
Practically a Master Poster
655 posts since Dec 2007
Reputation Points: 431
Solved Threads: 116
 

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

fatalbert55
Newbie Poster
2 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You