I am trying to link a project with the following command:
g++ build/test.o -o bin/test -pthread -L lib -L /home/alexander/opt/lib -lboost_thread-mt
which results in the following errors:
/usr/bin/ld: cannot find -lboost_thread-mt
collect2: error: ld returned 1 exit status
However, the boost libraries are installed in the directory /home/alexander/opt/lib. Why does the linker do not find the boost libraries? I also tried to link with -I instead if -L with the same outcome...
Content of /home/alexander/opt/lib is /home/alexander/opt/lib/boost_1_57_0.
change libboost_thread-mt to libboost_thread, first find the address of libboost_thread.so and libboost_thread.a then make softlinks to these files in the same address,
so it should be:
ln -s /...libboostSourceFiles.../libboost_thread.so /..RequestTOmtFiles.../libboost_thread-mt.so
it works for other libboost -mt files too, like serialization , iostreams, programoptions
Related
I am compiling an opensource project to run on my machine which is this project. It requires boost library so I installed the Boost_1_55 library on my ubuntu machine but the compiling process was not successfully finished by printing out some error messages as follows.
libtool: link: g++ -g -O3 -Wall -DKENLM_MAX_ORDER=6 -W -Wall -Wno-sign-compare -I./.. -pthread -I/usr/include -g -O2 -o .libs/query query_main.o ./.libs/libklm.so ../util/.libs/libklm_util.so -lz -L/usr/lib/x86_64-linux-gnu -lboost_program_options -lboost_thread -lboost_system -lpthread -lrt -pthread
../util/.libs/libklm_util.so: undefined reference to `boost::thread::join()'
../util/.libs/libklm_util.so: undefined reference to `boost::thread::~thread()'
./.libs/libklm.so: undefined reference to `boost::thread::start_thread()'
collect2: ld returned 1 exit status
This answer seems the solution for my problem but the result of ls -al /usr/local/lib | grep thread showed me like below.
libboost_thread.a
libboost_thread.so -> libboost_thread.so.1.55.0
libboost_thread.so.1.49.0
libboost_thread.so.1.55.0
I don't know what else to check more. Thank you in advance for your help.
You can try to add /usr/local/lib to LD_LIBRARY_PATH like this
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
You have the static Boost library object (libboost_thread.so) but do you have the Boost development files installed? Check to see if the /usr/include/boost/thread directory exists and has *.hpp files in it. If not you may need to install the libboost-thread-dev package for your distribution or download the header files directly from Boost.org.
I am compiling a C++ application using GNU g++. The project takes advantage of OpenSSL libraries.
Background
On my machine (a 64 bit CentOS quad core) I compile and link my files.
g++ -g -c -L/usr/local/lib/ -L/usr/lib64/
-I/usr/local/include/ -I/usr/local/ssl/include/
-lcrypto mysrc1.cpp mysrc2.cpp mysrc3.cpp
g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto
*.o -o ./myapp.out
My application uses function MD5 which is contained in libcrypto.so. As you can see I specify to g++ the dirs where to search using the -L, -I options and which libraries to look for with the -l<lib-name> option. There are some trivial paths like /usr/local/lib which can be omitted of course, but I specified them because the makefile is parametric.
The problem
My problem is that I can successfully compile my stuff (first command), but linking fails (second command):
/usr/bin/ld: cannot find -lcrypto
collect2: ld returned 1 exit status
make: * [cppsims_par] Error 1
But I did check folders and everything... libcrypto.so is inside /usr/lib64/. What is going on?
It may help if you try strace to find why it failed the file lookup
strace -f -e trace=file g++ -L/usr/local/lib/ -L/usr/lib64/ -lcrypto
*.o -o ./myapp.out
I did find the problem and it is related to this question: ld cannot find an existing library
Actually I had no symlink libcrypto.so and the compiler was not able to find the library...
I had related issue, and resolved it after inspecting the trace.
I had
-L<my/path/to/lib> -llib_some_library
when it should have been
-L<my/path/to/lib> -lsome_library
I have the following files on my computer.
/lib64/libm.so.6
/usr/lib64/libm.so
but when I link with the following, I get errors
$ g++ -L/usr/lib64 -O3 -static -Wall -Wno-char-subscripts -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -IMSToolkit/include Comet.o Threading.o CometSearch.o CometPreprocess.o CometPostAnalysis.o CometMassSpecUtils.o CometWriteOut.o CometWriteSqt.o CometWritePepXML.o -LMSToolkit -lmstoolkitlite -o comet.exe
/usr/bin/ld: cannot find -lm
collect2: ld returned 1 exit status
$
Does anyone knows why?
Yes I do. You are trying to link a static exe with no shared libraries - the libraries you have are shared because of the .so extension - you need to install libm.a
Either remove the -static option or install the .a versions of the library
I am trying to build some software on a brand new install of CentOS 5.5
My compile line is :
g++ -I ../common/ -I ../readers/ -I ../writers/ -I /home/dcole/software/xerces-c-3.1.1/src -O3 -Wall -fopenmp -fPIC -o chipper chipper.cpp -L/usr/lib64/ ../../lib/IDT.a ../../lib/Linux/libxerces-c.a -lcurl -lidn -ldl -lssl ../../lib/Linux/libfftw3f.a -lpthread -lm
and I am getting
[exec] /usr/bin/ld: cannot find -lcurl
[exec] collect2: ld returned 1 exit status
Even though I can actually see the lib
$ /sbin/ldconfig -p | grep curl
libcurl.so.3 (libc6,x86-64) => /usr/lib64/libcurl.so.3
libcurl.so.3 (libc6) => /usr/lib/libcurl.so.3
So why cant g++ see it?
At link time, -lcurl tells the linker to look for libcurl.so.
From there, the SONAME within the library (libcurl.so.3) is embedded into the executable, and that's the filename that is searched for when executing.
You have libcurl.so.3 but may be lacking libcurl.so, which is needed for development.
What is your distribution? Usually there will be a second package with development headers/libraries, separate from the runtime bits.
Copy the file from any source /usr/lib/libcurl.so and place it in /usr/lib/, then try to compile. It will work out.
I'm trying to use the Boost Libraries ... but to no avail. I attempted to follow the Getting Started tutorial on Boost's website (for Unix Variants), but having problems along the way.
I compiled the libraries into a directory in my Downloads folder:
/Users/myUsername/Downloads/boostCompiled
When I use the full path to the library ... The example program (given on the Boost Website) compiles and links fine.
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ /Users/myUsername/Downloads/boostCompiled/lib/libboost_regex.a
However, when I attempt to link the using the -L and -l options ... it fails ...
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l boost_regex
ld: library not found for -lboost_regex
collect2: ld returned 1 exit status
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l libboost_regex
ld: library not found for -llibboost_regex
collect2: ld returned 1 exit status
g++ -o boostTesting boostTesting.cpp -I /Users/myUsername/Downloads/boostCompiled/include/ -L /Users/myUsername/Downloads/boostCompiled/lib/ -l regex
ld: library not found for -lregex
collect2: ld returned 1 exit status
My shell is bash ... and I've set my DYLD_LIBRARY_PATH to the following:
export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:/Users/myUsername/Downloads/boostCompiled/lib
It appears I'm not using the correct name to link (with the -l) option. Can somebody please help! Thanks in advance!
There shouldn't be a space between -L and /Users/myUsername/Downloads/boostCompiled/lib/
Make sure that libboost_regex.a is compiled in /Users/myUsername/Downloads/boostCompiled/lib.
Then this should work:
g++ -o boostTesting boostTesting.cpp -I/Users/myUsername/Downloads/boostCompiled/include/ -L/Users/myUsername/Downloads/boostCompiled/lib/ -lboost_regex