Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

G++ cannot find boost library

I am not good in command-line compiling. My problem is inability to compile simple project, that depends from Boost. The following is a log of my trying:

$ g++ -Wall test.cpp -o main
/tmp/ccCTvBYE.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x6b): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x77): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x83): undefined reference to `boost::system::system_category()'
/tmp/ccCTvBYE.o: In function `boost::asio::error::get_system_category()':
test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status

So, there I found instructions for adding-lboost_system or -lboost_system-mt. I got the following:

$ g++ -lboost_system -Wall test.cpp -o main                                                                                                                    
/usr/bin/ld: cannot find -lboost_system
collect2: error: ld returned 1 exit status

$ g++ -lboost_system-mt -Wall test.cpp -o main                                                                                                                 
/usr/bin/ld: cannot find -lboost_system-mt
collect2: error: ld returned 1 exit status

I tried to locate boost_system library.

$ /sbin/ldconfig -p | grep boost_system
    libboost_system.so.1.53.0 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0

Then I unsuccessfully tried the following

$ g++ -I"/home/third_party/boost/" -L"/usr/lib/x86_64-linux-gnu/" -lboost_system -Wall test.cpp -o main
/usr/bin/ld: cannot find -lboost_system
collect2: error: ld returned 1 exit status

Now I am stuck. How to form the command to compile?

Edit:

The following trying didn't help, too.

ln -s /usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0 /usr/lib/x86_64-linux-gnu/libboost_system.so
ldconfig -n /usr/lib/x86_64-linux-gnu/

$ ll /usr/lib/x86_64-linux-gnu/ | grep boost_system
lrwxrwxrwx   1 root root       51 янв.  21 19:47 libboost_system.so -> /usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0
-rw-r--r--   1 root root    14536 окт.  13 07:14 libboost_system.so.1.53.0

$ g++ -I"/home/third_party/boost/" -L"/usr/lib/x86_64-linux-gnu/" -lboost_system -Wall -m64 boost_async.cpp -o main
/tmp/ccE20K2W.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x6b): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x77): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x83): undefined reference to `boost::system::system_category()'
/tmp/ccE20K2W.o: In function `boost::asio::error::get_system_category()':
test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status
like image 583
Loom Avatar asked Jan 21 '14 15:01

Loom


People also ask

Is Boost a standard C++ library?

Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work well with the C++ Standard Library. Boost libraries are intended to be widely useful, and usable across a broad spectrum of applications.

What is the use of Boost library in C++?

Boost is a set of libraries for the C++ programming language that provides support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It contains 164 individual libraries (as of version 1.76).

Where are header files in Boost?

5.1 Easy Build and Install will leave Boost binaries in the lib/ subdirectory of your installation prefix. You will also find a copy of the Boost headers in the include/ subdirectory of the installation prefix, so you can henceforth use that directory as an #include path in place of the Boost root directory.


1 Answers

If you place the linker directive -lboost_system at the end of the command line like so:

g++ -I"/home/third_party/boost/" -L"/usr/lib/x86_64-linux-gnu/" -Wall -m64 boost_async.cpp -o main -lboost_system

this should solve the problem. Thanks to Colin D Bennett and wesley.mesquita for clarifying this answer.

like image 121
amcn Avatar answered Oct 14 '22 07:10

amcn