简体   繁体   中英

Cannot compile C++ program with custom header files in Linux

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.

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM