-
January 11th, 2009, 09:44 AM
#1
[Static Libraries Linking] undefined reference to
Hello, I say for first I'm a beginner and this is the first time I try to link a static library (created by me) in a test application. I've looked for a solution over hundreds of sites but nothing fits my situation or works as well.
Here's the problem:
I compile file.cpp as static library and I get libfile.a which seems as a nice static library at all. Now, on the mainApp.cpp, what should I do? I wrote #include "file.h" (a header file with signatures of the file.cpp that I put in the same folder) and I tried to compile with g++ using -L"home/user/folder" (main folder where library and app are) and -lfile but when compiling it gave a lot of errors on mainApp.cpp saying every object defined in the library were underfined references.
E.g.
undefined reference to "VError::Message()"
When looking for a solution I noticed it is a very common problem for beginner programmers but there's no clear explanation also on tutorial and how-tos.
Thanks for interesting.
valleyman
-
January 11th, 2009, 10:03 AM
#2
Re: [Static Libraries Linking] undefined reference to
Off the top of my head...
Code:
g++ -c mainApp.cpp
g++ mainApp.o library.a -o mainApp
should do the trick...
-
January 11th, 2009, 02:10 PM
#3
Re: [Static Libraries Linking] undefined reference to
Also, start using an IDE. As the application grows big and you have more libs (yours and 3rd party), the command line gets longer and unmanageable. makefiles are good too but very tricky to get right. IDE's do that job for you.
Recently, I tried out NetBeans 6.5 and it looked very promising. Very nice. I did that on windows though with cygwin installed having g++/mingw, gdb as debugger, GNU make utility for makefiles all integrated into the IDE. That's just a one time setup. Then there are other IDEs too like : code::blocks, Eclipse which are good too. And they work on Linux as well as windows.
Since, you are using g++ hence I provided the above options (assuming you are working on Unix/Linux). If you are actually using mingw port on windows - I would also recommend on using Visual C++ express editions that are freely available. It is stripped version as compared to the professional ones that need to be bought though.
Can you help me with my homework assignment?, Before you post!, Use code tags, How to post!, Codeguru technical FAQs, C++ FAQ Lite, Stroustrup: C++ Style and Technique FAQ, Guru of the Week, Comeau C and C++ FAQs, Comeau C++ Templates FAQs, CUJ @ DDJ, Spam threshold
My Blogs : Learning C++ is fun | Abnegator's reflections
Open Threads : C++ Aha! Moments | Nature of work in C++?
-
January 11th, 2009, 02:19 PM
#4
Re: [Static Libraries Linking] undefined reference to
@Andreas Masur: thanks for the help, but compiling that way I still get the same bunch of errors
@exterminator: I usually use Eclipse, but now I started compiling the files on my own to simplify the process as I got the same errors with Eclipse integrated compiler (g++).
any ideas??
-
January 11th, 2009, 05:36 PM
#5
Re: [Static Libraries Linking] undefined reference to
Originally Posted by valleymannn
@exterminator: I usually use Eclipse, but now I started compiling the files on my own to simplify the process as I got the same errors with Eclipse integrated compiler (g++).
1) Maybe you didn't specify the static library to use in Eclipse correctly.
2) Maybe there truly are no functions that you claim are in the static library. Just because a static library exists that you created doesn't mean that those functions are actually there. Maybe they are in a namespace and you forgot to specify them as being in a namespace in your source code, or vice-versa, or there is a preprocessor symbol that needs to be defined in your main() app, who knows. The possibilities are endless...
Basically, we have to believe what you're telling us, as we do not have access to your machine or files that you say you're compiling. Therefore you should provide as much detail as possible in what you're doing. Too many times, posters who claim they're doing "this and that" are not doing "this and that".
Regards,
Paul McKenzie
-
January 11th, 2009, 07:33 PM
#6
Re: [Static Libraries Linking] undefined reference to
youre right but I'm not saying some of the functions of the library are unrecognized, I'm *all* of them aren't, and those are functions which perfectly worked when the big library source code was in the same file where main() function is.
I know that this still doesn't say anything but this is the only way I can explain withouth showing the whole situation (the program is about 1 thousand lines long, pretty long to synthetize) but for those who might be available to help I could send the code to let them understand better...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|