PDA

View Full Version : Linking to cpp-netlib




Wnt2bsleepin
Aug 8, 2013, 12:24 PM
I am trying to link my simple program to cpp-netlib. I downloaded and extracted the distribution, then ran the make file. It seems to find the header files fine, but it cannot find the libraries.

Here is my command that I am running to compile.

g++ Test.cpp -o Test -I/usr/local/cpp-netlib-0.10.1/ -l/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-client-connections.a -l/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-server-parsers.a -l/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-uri.a

However, it is saying the libraries are not found.

ld: library not found for -l/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-client-connections.a
collect2: ld returned 1 exit status

Cross posted (http://www.dreamincode.net/forums/topic/326632-where-to-put-libraries-osx/page__gopid__1886352&#entry1886352) over at DreamInCode. Any help is much appreciated.



ElectricSheep
Aug 8, 2013, 01:51 PM
g++ Test.cpp -o Test -I/usr/local/cpp-netlib-0.10.1/ -l/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-client-connections.a -l/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-server-parsers.a -l/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-uri.a

You are not using -l correctly here. The -l option instructs gcc to take the supplied argument, prepend it with "lib" and append ".a", and then traverse the Libraries search paths looking for a corresponding object file to link to. In your case, gcc is literally taking "/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-client-connections.a" and searching for "lib/usr/local/cpp-netlib-0.10.1/build/libs/network/src/libcppnetlib-client-connections.a.a". Clearly its not going to find anything to link against.

Either specify the full path to the object code you wish to statically link in without the -l flag, or include a search path with -L and use -l as such:

g++ Test.cpp -o Test -I/usr/local/cpp-netlib-0.10.1/ -L/usr/local/cpp-netlib-0.10.1/build/libs/network/src/ -lcppnetlib-client-connections -lcppnetlib-server-parsers -lcppnetlib-uri