6

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
Community
  • 1
  • 1
Loom
  • 9,768
  • 22
  • 60
  • 112
  • @Jmc - Thank you. Unfortunately, it didn't help – Loom Jan 21 '14 at 15:19
  • Are you using `bjam`? – Elliott Frisch Jan 21 '14 at 15:19
  • Sorry.. my ideas were no good. I was thinking maybe it's the version numbers after the library name. You could try creating a link to libboost_system.so that links to libboost_system.so.1.53.0 in the /usr/lib/x86_64-linux-gnu/ directory – Jmc Jan 21 '14 at 15:20
  • @ElliottFrisch - Boost built with the earlier on this computer. And it available from compiling other projects with `CMakeLists.txt`. – Loom Jan 21 '14 at 15:26
  • @ElliottFrisch - I wrote, that I've tried `/sbin/ldconfig -p | grep boost_system`. Do you mean this `ldconfig` call? – Loom Jan 21 '14 at 15:27
  • Can you try adding `-m64` to the build? It's a reach... but your build looks correct. – Elliott Frisch Jan 21 '14 at 15:33
  • @ElliottFrisch - Unfortunately, `-m64` didn't help – Loom Jan 21 '14 at 15:38
  • Can you try linking the lib to exclude the version number? Try `ln -s /usr/lib/x86_64-linux-gnu/libboost_system.so.1.53.0 /usr/lib/x86_64-linux-gnu/libboost_system.so` and try it again with the same include path. – Robin Jan 21 '14 at 15:40
  • @Robin After that, remember to run `ldconfig` again! – Elliott Frisch Jan 21 '14 at 15:41
  • @Robin, ElliottFrisch - Thank you. However, didn't help. (I expand the questions with this try – Loom Jan 21 '14 at 15:51
  • 1
    Try placing the link directives at the end of command line after the ```-o main``` part. – amcn Jan 21 '14 at 16:39
  • @amcn - I'm novice. what is _link_ _directives_? – Loom Jan 21 '14 at 16:57
  • 1
    The link directive is the `-lMYLIB` – Colin D Bennett Jan 21 '14 at 16:59
  • 1
    I don´t an linux env to verify, but try `g++ -I"/home/third_party/boost/" -L"/usr/lib/x86_64-linux-gnu/" -Wall test.cpp -o main -lboost_system`(note the `-lboost_system` at the end). – wesley.mesquita Jan 21 '14 at 17:13
  • 2
    @Loom - I meant put the -lboost_system at the end of the command. Apologies if my wording was unhelpful. Wesley and Colin explained it better than I did. – amcn Jan 22 '14 at 11:15
  • @Loom - Sure thing. Glad you got it sorted. – amcn Jan 22 '14 at 13:39

1 Answers1

12

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.

Community
  • 1
  • 1
amcn
  • 428
  • 5
  • 7