Hi, I am newbie to c/cpp and I have linking and/or loading shared library problem. I can not link with dynamic libraries. Thanks for your help in advance, Tamas *** 1 *** [violin]$ ldconfig -p | grep libboost_program_options libboost_program_options.so.1 (libc6) => /usr/lib/libboost_program_options.so.1 *** 2 *** As I do not have the file /usr/lib/libboost_program_options.so.1 I created a link: libboost_program_options.so.1 -> libboost_program_options-gcc-1_33_1.so.1.33.1 *** 3 *** Compiling my src file [violin]$ g++ -Wall -I /usr/local/include/boost-1_33_1 -c test.cpp *** 4A *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options-gcc-1_33_1.so.1.33.1 [violin]$ ./test ./test: error while loading shared libraries: libboost_program_options-gcc-1_33_1.so.1.33.1: cannot open shared object file: No such file or directory *** 4B *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options.so.1 [violin]$ ./test ./test: error while loading shared libraries: libboost_program_options-gcc-1_33_1.so.1.33.1: cannot open shared object file: No such file or directory *** 4C *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options-gcc-1_33_1.a [violin]$ ./test Compression level was not set. -- Tamas Hegedus, PhD | phone: (1) 919-966 0329 UNC - Biochem & Biophys | fax: (1) 919-966 5178 6107 Thurston-Bowles Bldg | mailto:hegedus@med.unc.edu Chapel Hill, NC, 27599-7248 | http://biohegedus.org
Tamas Hegedus wrote: ...
*** 1 *** [violin]$ ldconfig -p | grep libboost_program_options libboost_program_options.so.1 (libc6) => /usr/lib/libboost_program_options.so.1
*** 2 *** As I do not have the file /usr/lib/libboost_program_options.so.1 I created a link: libboost_program_options.so.1 -> libboost_program_options-gcc-1_33_1.so.1.33.1
Here the libraries are in /usr/lib.
*** 3 *** Compiling my src file [violin]$ g++ -Wall -I /usr/local/include/boost-1_33_1 -c test.cpp
*** 4A *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options-gcc-1_33_1.so.1.33.1
Here you link with /usr/local/lib/...
[violin]$ ./test ../test: error while loading shared libraries: libboost_program_options-gcc-1_33_1.so.1.33.1: cannot open shared object file: No such file or directory
I'm guessing that it looks for the lib in /usr/local/lib. What does ldd ./test say? Try expanding LD_LIBRARY_PATH with /usr/local/lib and see if this helps.
*** 4B *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options.so.1
[violin]$ ./test
../test: error while loading shared libraries: libboost_program_options-gcc-1_33_1.so.1.33.1: cannot open shared object file: No such file or directory
... HTH, Markus
The syntax is wrong. You should do g++ -Wall -o test test.o -L /usr/local/lib -lboost_program_options -L for the location, -l for the library file's name (dropping the lib at the beginning and the .so at the end), and preferably without space between -l and the library's name. assuming "/usr/local/lib/libboost_program_options.so" is a link to the library file. Tamas Hegedus wrote:
Hi,
I am newbie to c/cpp and I have linking and/or loading shared library problem.
I can not link with dynamic libraries.
Thanks for your help in advance, Tamas
*** 1 *** [violin]$ ldconfig -p | grep libboost_program_options libboost_program_options.so.1 (libc6) => /usr/lib/libboost_program_options.so.1
*** 2 *** As I do not have the file /usr/lib/libboost_program_options.so.1 I created a link: libboost_program_options.so.1 -> libboost_program_options-gcc-1_33_1.so.1.33.1
*** 3 *** Compiling my src file [violin]$ g++ -Wall -I /usr/local/include/boost-1_33_1 -c test.cpp
*** 4A *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options-gcc-1_33_1.so.1.33.1
[violin]$ ./test ./test: error while loading shared libraries: libboost_program_options-gcc-1_33_1.so.1.33.1: cannot open shared object file: No such file or directory
*** 4B *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options.so.1
[violin]$ ./test
./test: error while loading shared libraries: libboost_program_options-gcc-1_33_1.so.1.33.1: cannot open shared object file: No such file or directory
*** 4C *** [violin]$ g++ -Wall -o test test.o /usr/local/lib/libboost_program_options-gcc-1_33_1.a
[violin]$ ./test Compression level was not set.
participants (3)
-
Hin-Tak Leung
-
Markus Schöpflin
-
Tamas Hegedus