![]() |
|
#1
|
|||
|
|||
Need some help with undefined reference compile errorHi, I've just recently started my new practical for uni, but when I go to compile my code, I get an error saying that:
Code:
I have been searching on the internet for the past hour or so trying to find a fix, but have had no luck. Can anyone help with how I can fix this? My code is as follows: hp-35.cpp - I didn't write this code, it was written by our lecturer, I have only added the includes and namespace stuff (he gave us the main function, it just wasn't wrapped in all the normal stuff for the class). CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: Need some help with undefined reference compile erroryou also need to compile HPStack.cpp. If you are only compiling hp-35.cpp then the definitions of HPStack are not being built and the linker is unable to find them.
What is the command you are using to compile? __________________
My personal site: Utilities for text processing, debugging, testing and plotting |
|
#3
|
|||
|
|||
Re: Need some help with undefined reference compile errorOh... I was merely typing
Code:
So it doesn't matter that I compile HPStack.cpp first, and then compile hp-35.cpp after? The linker still won't be able to find them? How would I go about compiling two at the one time? |
|
#4
|
|||
|
|||
Re: Need some help with undefined reference compile errorI have just found on another website about including HPStack.cpp in my hp-35.cpp file by doing
Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
Does this seem valid? It appears to work, but I'm not sure if it's going to be limited use or not. Thanks |
|
#5
|
|||
|
|||
Re: Need some help with undefined reference compile errorThanks for the reply dave.
With the command line you gave, could you please give a quick explanation as to what the -Wall -W and -pedantic stand for? Other than that it looks pretty simple how to fix the problem Thanks |
|
#6
|
|||||
|
|||||
Re: Need some help with undefined reference compile errorQuote:
For the benefit of others, here's what I said (more-or-less) Quote:
Now, back to the present: Quote:
After you get more experienced, you may decide to turn off some of the warning flags or to ignore certain types of warnings, but for now, I recommend that you let the compiler help you as much as it can. In other words, turn on the warning switches and make whatever changes you need in order to get a "clean" compile: no warnings, no errors. Now, back to your code; Compiling your two C++ files together into a single program won't work, since you have, for some reason, put a main() function in each of them. Programs like this always have exactly one main() function. Lose the entire main() function in HPStack.cpp and try my command line for compiling. I think that you will still get the error message something like Code:
In the header file you have declared a constructor: CPP / C++ / C Code:
Now, if you don't declare a constructor, the compiler will helpfully supply a default, but if you declare a constructor, then you simply must supply an implementation. Plan 1: If you don't want your constructor to do anything "special," you can just comment out the HPStack() line in the header. Plan 2: Since you might someday want to make the constructor do something interesting, you supply "placeholder" code for a constructor, but give it an empty block. That is, leave the header file as is and in HPStack.cpp, you can add a line or two something like: CPP / C++ / C Code:
Now try the compile stuff again. Regards, Dave Footnote: For a reference on compiler warnings, and to see what kind of probably-unfortunate-but-not-strictly-illegal code gets flagged by these warnings, see http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html |
|
#7
|
|||
|
|||
Re: Need some help with undefined reference compile errorThankyou very much dave! I have used the command line compile code you suggested, and I already have the empty constructor from post #4 in this thread.
I compiles the same as it was before, although I'm sure this is a must more efficient way for it to work. Thanks again |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Two-Tier data dissemination code installation problem | nidhibansal1984 | Computer Software Forum - Linux | 6 | 16-Sep-2007 11:13 |
| Linked Lists advice request | promsan | C Programming Language | 74 | 23-May-2007 09:29 |
| Major newbie problem | cynack | MS Visual C++ / MFC Forum | 1 | 08-Apr-2007 12:25 |
| Winsock error when compiling FLTK 2.0 Projects | mauriciorossi | FLTK Forum | 3 | 16-Aug-2005 11:18 |
| Help with syntax errors | PeteGallo | C Programming Language | 7 | 08-Aug-2005 21:30 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The