C++ Boost: undefined reference to `boost::system::detail::system_category_ncx()` - c++

I am trying to use Microsoft REST SDK to create a server listening to HTTP requests. My current computer is Ubuntu 18.04, the server code is pretty simple.
I have already installed the library by following the instructions on libboost official website and I have checked files in /usr/local/lib/, there are libboost_random.so.1.68.0 so I presume that I have libboost library.
However when I try to compile the code with the following command:
g++ server.cpp -o server -lpthread -lcpprest -lcrypto -lssl -lboost_system
It shows:
/tmp/ccKWADuo.o: In function `boost::system::system_category()':
server.cpp:(.text._ZN5boost6system15system_categoryEv[_ZN5boost6system15system_categoryEv]+0x7): undefined reference to `boost::system::detail::system_category_instance'
/tmp/ccKWADuo.o: In function `boost::system::generic_category()':
server.cpp:(.text._ZN5boost6system16generic_categoryEv[_ZN5boost6system16generic_categoryEv]+0x7): undefined reference to `boost::system::detail::generic_category_instance'
collect2: error: ld returned 1 exit status
Thanks for any advices.

Boost consists of several independent libraries. Your linker error suggests you are missing libboost_system.so. You just mentioned libboost_random.so to be in your /usr/local/lib but is there also the required libboost_system.so?

[Problem solved] Reinstalling library libboost 1.68.0 helps. Error occurs when building from source, fixing those building errors will solve the problem.

Related

CImg library when compiling return undefined reference to `__imp_SetDIBitsToDevice'

I'm using VSCode on Windows 10 with MinGW compiler installed. I've tried using CImg library to edit images (http://cimg.eu/), and when I'm trying to compile code from tutorial (http://cimg.eu/reference/group__cimg__tutorial.html) I get this error:
C:\Users\Martini\AppData\Local\Temp\ccBswQ5w.o:tutorial.cpp:(.text$_ZN12cimg_library11CImgDisplay5paintEv[_ZN12cimg_library11CImgDisplay5paintEv]+0xba): undefined reference to `__imp_SetDIBitsToDevice'
collect2.exe: error: ld returned 1 exit status
I have CImg.h file located in folder with tutorial.cpp. Here's command I'm using to compile:
g++ tutorial.cpp -o tutorial.exe
It's my first time working with libraries in C++, and CImg looks fairly easy to use, but if you have used other libraries to edit photos, let me know.
Thanks in advance!
You need to link to GDI32 on Windows I think. Something like:
g++ tutorial.cpp -lgdi32 -o tutorial.exe

Boost library issues

I am trying to compile a simple c++ program using g++ which contains boost includes but i am getting the following error. I installed it from the tar file found in the boost site. I get the following error only with the asio library.
$ g++ -std=c++03 -Wall -pedantic -g -O2 tcp.cpp -lboost_system -lboost_date_time -lboost_thread -lboost_asio
/usr/bin/ld: cannot find -lboost_asio
collect2: error: ld returned 1 exit status
Boost Asio is header only.
Drop -lboost_asio
ASIO doesn't have a library built for it, so indicating -lboost_asio as an option doesn't really make sense.
However, ASIO does have a dependency on boost.system, which does require a library be built for it.
Make sure you've properly built the boost library in the first place (correct optimization flags, correct Runtime-Library linking, correct architecture, and so on), and that the generated library files (the .so files, in your case) are accessible to the executable.

Boost and ssl client server building issue on Linux

I have installed boost as a third library when I install pcl (Point Cloud Library).
Now I am trying to run client and server programs http://www.boost.org/doc/libs/1_57_0/doc/html/boost_asio/example/cpp03/ssl/client.cpp
When trying to link the required libraries:
g++ -I /usr/include/boost/ server.cpp -o server -lboost_system -lssl -lpthread
following error appears:
/usr/bin/ld: /tmp/ccRbD849.o: undefined reference to symbol
'ERR_reason_error_string##OPENSSL_1.0.0'
//lib/x86_64-linux-gnu/libcrypto.so.1.0.0: error adding symbols: DSO
missing from command line collect2: error: ld returned 1 exit status
When I searched the usr folder the Boost folder exists only inside include subfolder.
What can I do to solve this problem.
[...] libcrypto.so: [...] DSO missing from command line
spells it out! You are missing
-lcrypto
on the linker command line. In fact I always use -lssl -lcrypto in tandem

compiling boost.asio using g++ compiler

I'm new to g++ compiler and also trying to start coding with boost.asio libraries, but have some difficulties compiling the code using g++.
I have installed boost libraries usingsudo apt-get install libboost-all-dev and boost folder is located in /usr/include directory, and whole scenario:
geek#ubuntu:~/workspace/HelloBoost/src$ g++ -I /usr/include/ -l boost_asio HelloBoost.cpp
/usr/bin/ld: cannot find -lboost_asio
collect2: ld returned 1 exit status
Thanks for your answers.
Did you read about using boost.asio ? Apparently, it looks like a headers only library, and you only need to link -lboost_system -lboost_regex -lopenssl

Compile C++ and OpenSSL on Ubuntu 11.10

I got a serious problem compiling my C++ and OpenSSL project on my Ubuntu 11.10.
The compiling command is:
g++ -Wall -lssl -lm -lcrypto -I ./src ./src/server.cpp -o ./bin/server
I receive these errors:
server.cpp:(.text+0x8ff): undefined reference to `RSA_new'
server.cpp:(.text+0x92d): undefined reference to `PEM_read_RSAPrivateKey'
server.cpp:(.text+0xa85): undefined reference to `RSA_size'
server.cpp:(.text+0xaa1): undefined reference to `RSA_size'
server.cpp:(.text+0xae7): undefined reference to `RSA_private_decrypt'
server.cpp:(.text+0xd84): undefined reference to `BF_set_key'
server.cpp:(.text+0xf1d): undefined reference to `BF_ecb_encrypt'
server.cpp:(.text+0x13c6): undefined reference to `BF_ecb_encrypt'
collect2: ld returned 1 exit status
make: *** [server] Error 1
I successfully installed openssl and libssl-dev but the problem persists.
I tried to compile the project on Linux Mint 12 with the kernel 3.0 and I had the same problem.
On my old Linux OS with the kernel 2.6 the project compiled and worked fine (using the same Makefile and the same sources).
Please help me!
Generally you need to have the -l link flags after the code that references them. Try
g++ -Wall -I ./src ./src/server.cpp -o ./bin/server -lssl -lm -lcrypto
As the comment to this answer states, the linker only looks for undefined symbols to include in the order the parameters are listed.
That is, if your cpp file uses the libraries, the libraries have to be listed after the cpp file.
Those error are from crypto library, check whether ssl and crypto libraries are available in /usr/lib or where ever u installed if not install them and have u set the library search path for libssl and libcrypto in your compiling command?