943,865 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1015
  • C++ RSS
Jul 1st, 2009
0

Help with compiler error for self-teacher

Expand Post »
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 ===|
Attached Files
File Type: cpp grade.cpp (587 Bytes, 12 views)
File Type: h grade.h (266 Bytes, 11 views)
File Type: cpp gradeCalc.cpp (1.6 KB, 12 views)
File Type: cpp median.cpp (643 Bytes, 16 views)
File Type: h median.h (142 Bytes, 12 views)
File Type: cpp Student_info.cpp (813 Bytes, 13 views)
File Type: h Student_info.h (450 Bytes, 12 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fatalbert55 is offline Offline
2 posts
since Jul 2009
Jul 1st, 2009
0

Re: Help with compiler error for self-teacher

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.
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 1st, 2009
1

Re: Help with compiler error for self-teacher

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.
Last edited by Agni; Jul 1st, 2009 at 10:55 am.
Featured Poster
Reputation Points: 431
Solved Threads: 116
Practically a Master Poster
Agni is offline Offline
654 posts
since Dec 2007
Jul 1st, 2009
0

Re: Help with compiler error for self-teacher

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fatalbert55 is offline Offline
2 posts
since Jul 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Winsock - talking over the internet
Next Thread in C++ Forum Timeline: Having problems with my word editor pprogram in API





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC