LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   unable to link against a 'c' shared library (https://www.linuxquestions.org/questions/linux-software-2/unable-to-link-against-a-c-shared-library-767877/)

vessper 11-09-2009 05:43 AM

unable to link against a 'c' shared library
 
Hello everybody.

This is my first post here and I have a problem that I am not able to solve for some time now.

I have written a piece of software on a MAC and have been attempting to port it to SuSe 11.1. The problem is that one of the libraries that is used by the code refuses to link. It could be because it doesn't like very much, but I am hoping that the explanation is simpler.

The library is called vl (http://www.vlfeat.org/). It is made in c and compiles fine. Thereafter I copy libvl.so to /usr/local/lib and the header files in /usr/local/include. My source compiles fine. The offending command is:

Quote:

g++ -L"/home/vess/phd/cpppoj/SFM/extern/libs" -L/usr/local/lib -L/usr/lib -o"SFM" [...object files here ...] -llog4cplus -llapack -lANN -lIL -lvl -lc -lILU
Quote:

undefined reference to `vl_sift_new(int, int, int, int, int)'
undefined reference to `vl_sift_process_first_octave...
undefined reference to `vl_sift_process_next_octave...
undefined reference to `vl_sift_detect(_VlSiftFilt*)'
[...]
collect2: ld returned 1 exit status
make: *** [SFM] Error 1
Running nm reports that all simbols are there. For example:
Quote:

$ nm /usr/local/lib/libvl.so | grep vl_sift_new
0000f030 T vl_sift_new
I am running the compilation from Eclipse where I have included all necessary paths, and /usr/local/lib is in /etc/ld.so.conf.

Please let me know what I am missing.

I will appreciate any help.
Cheers

timmeke 11-09-2009 08:12 AM

Did you check versioning of the libraries? Perhaps the interfaces have changed between versions, messing up the linking.
Not a g++ expert, but does the order of the parameters matter for the g++ command above? ie do you not need to put the -l options
before the .o files?
Might want to have a look at LD_LIBRARY_PATH environment variable too.

maslik 11-09-2009 10:16 AM

Is your software written in C or C++? I had a similar problem while I was trying to link a C++ program against C ffmpeg library. As a solution I had to use wrap the includes with extern "C" to make it work. But it looks like, that your piece of software is written in C, because the compiler doesn't try to link against the functions with C++ decorations. As mentioned above it may really be because of different compiler versions.

vessper 11-09-2009 10:47 AM

Yes, yes, yes! That is it! My software is C++ while the library is C. I just added:

Quote:

extern "C" {
#include "vl/sift.h"
}
And it compiled. Finally! It is an issue of using a C library into a C++ code. Half an hour ago i deiscoverd this link http://developers.sun.com/solaris/articles/mixing.html. It explains a lot about mixing C and C++.

Thanks a lot maslik!

maslik 11-09-2009 10:49 AM

I'm glad I could help you :).


All times are GMT -5. The time now is 05:09 PM.