0

I'm new to C++ and I'm having some trouble trying to compile my program. I have a Driver.cpp file which contains main(), and 2 header files each with corresponding .cpp files. They are all in the same directory. The Driver.cpp file only calls a function in one of the other header files, which does the rest of the work. My problem is I cannot compile the code as I keep getting "Undefined symbol first referenced in file" errors. I've tried many different ways of writing the compile code but none works. Here is one I tried:

"g++ -lm -o outputfile headerOne.cpp headerTwo.cpp Driver.cpp" 

If anyone can help me out I'd greatly appreciate it. Thanks!

Edit: By the way, I tried this code in Visual Studio before I put it into Linux and it worked. Not sure if that means anything, but thought I'd add that in here. Let me know if I need to attach some code.

3
  • 2
    Can you post some code? Maybe the header and implementation files if they are not too large... What is the exact error message? Where is this function supposed to be implemented? Commented Feb 19, 2013 at 21:45
  • Usually, "Undefined symbol" means the compiler could not find the definition. This would mean that some header file is not being included or the definition is skipped due to conditional compilation. Commented Feb 19, 2013 at 21:49
  • You will have to post more or most of the code. Commented Feb 19, 2013 at 21:59

2 Answers 2

1

I figured it out! Turns out I didn't have some variables defined in my .cpp files as "extern" in my .h files and I was missing "inline" in my function definitions. Thanks anyway for all your help!

Sign up to request clarification or add additional context in comments.

Comments

0

Since your code works in visual studios I am going to assume your includes are proper read this link it might give you some guidance for linux environment

http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.