kung fu buntu
June 15th, 2008, 05:17 AM
I am trying to use a third party library (not something from the repos) with my application, but ld complains that it can't find the symbol.
The command is more or less like this:
g++ -Wall -ansi -pedantic -pthread -I<source code dir with foobar.h/cpp> -L<dir with libfoobar.a> -lfoobar
And in my code I:
#include <foobar.h>
The compiler understands "things" because I don't have any compilation error. For example, if I call a bogus method it says that the class has no member named like that.
So, the problem is likely with ld.
By just declaring a foobar variable in my code I get:
g++ -Wall -ansi -pedantic -pthread -I<source code dir with foobar.h/cpp> -L<dir with libfoobar.a> -lfoobar main.cpp -o application
/tmp/ccr82f9q.o: In function blahblah:
file.cpp:80: undefined reference to `foobar::foobar(int)'
file.cpp:84: undefined reference to `foobar::~foobar()'
collect2: ld returned 1 exit status
make: *** [all] Error 1
*** Exited with status: 2 ***
FWIW, I was able to build the 3rd party lib without much problems. Although a weird thing I noticed is that even though its a C++ application it is built with GCC.
And I've tried in the past to build my c++ application with with GCC and it didn't work :-/
I have tried to also use the same compilation command (but using g++) than a sample application for the 3rd party lib, which has a series of -lfoobardep1 -lfoobardep2, but it didn't work. I got exactly the same error :(
I also tried copying foobar.h to my application dir but that didn't help anything either.
Does this has anything to do with static or dynamic linking, or the use of foobar.a or foobar.so, or LD_LIBRARY_PATH?
I don't have any foobar.so so I'm assuming it's like linking with any other lib in /usr/lib/
Do I have to pass any flags to ld?
I've been at this several hours and don't know what to do! :(
I'm desperate! :(
It's a long story... but if I can't get this to work... I'm dead
How can I solve this?
Thank you very much.
The command is more or less like this:
g++ -Wall -ansi -pedantic -pthread -I<source code dir with foobar.h/cpp> -L<dir with libfoobar.a> -lfoobar
And in my code I:
#include <foobar.h>
The compiler understands "things" because I don't have any compilation error. For example, if I call a bogus method it says that the class has no member named like that.
So, the problem is likely with ld.
By just declaring a foobar variable in my code I get:
g++ -Wall -ansi -pedantic -pthread -I<source code dir with foobar.h/cpp> -L<dir with libfoobar.a> -lfoobar main.cpp -o application
/tmp/ccr82f9q.o: In function blahblah:
file.cpp:80: undefined reference to `foobar::foobar(int)'
file.cpp:84: undefined reference to `foobar::~foobar()'
collect2: ld returned 1 exit status
make: *** [all] Error 1
*** Exited with status: 2 ***
FWIW, I was able to build the 3rd party lib without much problems. Although a weird thing I noticed is that even though its a C++ application it is built with GCC.
And I've tried in the past to build my c++ application with with GCC and it didn't work :-/
I have tried to also use the same compilation command (but using g++) than a sample application for the 3rd party lib, which has a series of -lfoobardep1 -lfoobardep2, but it didn't work. I got exactly the same error :(
I also tried copying foobar.h to my application dir but that didn't help anything either.
Does this has anything to do with static or dynamic linking, or the use of foobar.a or foobar.so, or LD_LIBRARY_PATH?
I don't have any foobar.so so I'm assuming it's like linking with any other lib in /usr/lib/
Do I have to pass any flags to ld?
I've been at this several hours and don't know what to do! :(
I'm desperate! :(
It's a long story... but if I can't get this to work... I'm dead
How can I solve this?
Thank you very much.