undefined reference to `boost::thread - c++

I am trying to link libgetfiles.so to main.cpp. I ran the following command:
sudo g++ main.cpp -L/ubuntu/test -lgetfiles -L/usr/local/lib/ -lboost_thread
It gives me the following error:
/ubuntu/test/libgetfiles.so: undefined reference to'boost::thread::start_thread_noexcept()'
/ubuntu/test/libgetfiles.so: undefined reference to 'boost::thread::join_noexcept()'
/ubuntu/test/libgetfiles.so: undefined reference to 'boost::system::system_category()'
/ubuntu/test/libgetfiles.so: undefined reference to 'boost::system::generic_category()'
How can I resolve them?
I have tried uninstalling and reinstalling boost libraries as well.
I have also tried the below command:
g++ main.cpp -L/ubuntu/test -lgetfiles -L/usr/local/lib/ -lboost_thread-mt
Both of them did not work for me.

If you manually build and install boost (i.e. specific version), you should check you already not have libboost-all-dev package installed inside /usr/lib. Try to rm /usr/lib/libboost* && rm -r /usr/include/boost and then build again.

Related

linking failed with undefined reference to libboost_thread

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.

Compiling/linking g++ using -m32 flag on 64bit System -> manually add -ldl?

It was a long long way, but I managed to include a shared file (libpi_pi_gcs2.so) included into C++ code under Linux Mint 17 Cinnamon 64-bit. Now as the dust is saddled I have a question left... let me summarize:
I copied libpi_pi_gcs2.so in usr/local/lib.
Trying to compile main.cpp with
g++ -Wall -o test main.cpp -lpi_pi_gcs2
faild, returning
/usr/bin/ld: skipping incompatible //usr/local/lib/libpi_pi_gcs2.so when searching for -lpi_pi_gcs2
/usr/bin/ld: cannot find -lpi_pi_gcs2
collect2: error: ld returned 1 exit status
I talked with my flatmate, and he guessed maybe the shared library is only 32bit compatible.
Using -m32 let me take a step forward! But yielding new errors.
I googled and it seemed like I needed C32 std libraries. And I installed:
apt-get install ia32-libs
Again the old error messages disappeared and new one arose, after googling around I installed:
apt-get install g++-multilib
Trying to compile it now using
g++ -Wall -o test -m32 main.cpp -lpi_pi_gcs2
Let to the error messages:
//usr/local/lib/libpi_pi_gcs2.so: undefined reference to `dlsym'
//usr/local/lib/libpi_pi_gcs2.so: undefined reference to `dlopen'
//usr/local/lib/libpi_pi_gcs2.so: undefined reference to `dlclose'
The solution was the following command:
g++ -Wall -o test -m32 main.cpp -lpi_pi_gcs2 -ldl
Now my question:
Is it necessary to explicitly state -ldl i.e. link with libdl.so because the -m32 flag declares everything what follows to be 32bit and hence the linker would without explicitly
writing -ldl search for a 32bit libdl.so? I guess mine is 64 bit I am working on a 64bit system.
What do you think? More details and background informations are appreciated.
Greetings,
newandlost

Boost link error occurs even though I'm including the library

I'm trying to build a boost-dependent project on TravisCI. When it runs the g++ command:
g++ -Wall -L/usr/lib -fopenmp -lboost_system -lboost_filesystem -o bin/test obj/data_parser.o obj/hmm.o obj/test.o
It gets this linking error:
data_parser.cpp:(.text+0x136a): undefined reference to `boost::system::generic_category()'
But not only am I including -lboost_system in the g++ command, I also know that /usr/lib/libboost_system.so exists.
This is on an Ubuntu/Linaro 4.6.3-1ubuntu5 system with g++ 4.6.3. I installed the boost libraries with:
sudo apt-get install libboost-dev libboost-filesystem1.46-dev libboost-iostreams1.46-dev libboost-system1.46-dev
Why won't this link correctly?
Put the libraries after the object files in the linker command.
The objects and libraries are linked in order; and library code is only linked if it's needed to resolve a reference in the currently linked objects. By putting them first, there are no unresolved references when they are processed, so no code is linked from them.

libmysqlclient_18 not found

I'm trying to connect to mysql with C++ and the MySQLConnector, but I'm getting "undefined reference" errors everytime I make calls to the connector.
example:
/usr/lib/libmysqlcppconn.so: undefined reference to `mysql_stmt_execute#libmysqlclient_18'
My OS is Ubuntu 13.04 VM, I'm using Eclipse CDT and I installed the packages:
sudo apt-get mysql-client
sudo apt-get mysql-server
sudo apt-get mysql-client
sudo apt-get libmysqlclient-dev
I'm wondering that the libs (libmysqlclient,..) are in the folder /usr/lib/x86_64-linux-gnu/
and not in /user/local/mysql/lib like often found on the net. Does this make any difference?
I also downloaded the C++ Connector (binaries) from Oracle and copied the lib directory to /usr/lib and the include directory to /usr/include, but still I'm gettind the undefined reference errors.
I configured Eclipse in a way that I get this compile command:
g++ -L/usr/lib -L/usr/lib/x86_64-linux-gnu -pthread -o "Proj" ./Client.o -lmysqlcppconn -lmysqlclient -lz -lm -ldl
Any ideas?

Unable to compile with openssl c++

I installed openssl through binaries and i have that exact files at that exact location.
But when compiling i face this error. any idea?
g++ main.cpp -I /usr/local/openssl/include/openssl/
In file included from main.cpp:1:0:
main.h:4:25: fatal error: openssl/evp.h: No such file or directory
compilation terminated.
update:
the below command did the job but i still face errors.
g++ main.cpp -I/usr/local/openssl/include -L/usr/local/openssl/lib main.cpp -lcrypto
/usr/local/openssl/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x1d): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x33): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x3d): undefined reference to `dlclose'
Any idea? :(
Solution :
g++ main.cpp -I/usr/local/openssl/include -L/usr/local/openssl/lib main.cpp -lcrypto -ldl
Change to:
g++ main.cpp -I /usr/local/openssl/include
as the include directive is including the name of the subdirectory.
Note you will have to add the openssl library to link with. I am not familiar with it but something like -lopenssl and add a directory to be searched to locate it using -L option. The full command would be something like (as I am guessing the lib directory and name of library for openssl):
g++ main.cpp -I/usr/local/openssl/include -L/usr/local/openssl/lib main.cpp -lopenssl
no space between -I and the path.