0

I am trying to compile The example of Blocking TCP echo client: using the Boost.build b2 command as following:

b2 linkflags=-lpthread toolset=gcc threading=multi link=static

But I am getting the following errors:

gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/lte_sim
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, addrinfo const&, addrinfo**, boost::system::error_code&)':
/home/ha/MIH/boost_1_49_0/boost/asio/detail/impl/socket_ops.ipp:2899: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `__static_initialization_and_destruction_0(int, int)':
Simulator_main.cpp:(.text+0x68f): undefined reference to `boost::system::generic_category()'
Simulator_main.cpp:(.text+0x69b): undefined reference to `boost::system::generic_category()'
Simulator_main.cpp:(.text+0x6a7): undefined reference to `boost::system::system_category()'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `boost::system::error_code::error_code()':
Simulator_main.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `boost::asio::error::get_system_category()':
Simulator_main.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x5): undefined reference to `boost::system::system_category()'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::clear<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event5clearINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::clear<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::wait<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event4waitINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::wait<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::signal<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event6signalINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::signal<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o: In function `void boost::asio::detail::posix_event::signal_and_unlock<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
Simulator_main.cpp:(.text._ZN5boost4asio6detail11posix_event17signal_and_unlockINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[void boost::asio::detail::posix_event::signal_and_unlock<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)]+0x47): undefined reference to `odtone::crash(odtone::bug, char const*, char const*, unsigned int, char const*)'
collect2: ld returned 1 exit status
    "g++"    -o "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/lte_sim" -Wl,--start-group "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/Simulator_main.o" "/home/ha/MIH/boost_1_49_0/bin.v2/libs/program_options/build/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/libboost_program_options.a"     -lrt -Wl,--end-group -g -static -pthread -lpthread
...failed gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi/lte_sim...
...skipped <p../../dist>lte_sim for lack of <p../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/threading-multi>lte_sim...
...failed updating 1 target...
...skipped 1 target..

I already have a JamFile with the contents:

install install
    : lte_sim
    : <location>../../dist
    ;
project lte_sim
    ;
exe lte_sim
    : Simulator_main.cpp
      /boost//program_options
    ;

So what is the solution for the problem?

Thanks a lot.

I tried "b2 linkflags=-lboost_system toolset=gcc" and I got the following errors

gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/lte_sim /usr/bin/ld: cannot find -lboost_system ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/Simulator_main.o: In function `boost::asio::detail::socket_ops::getaddrinfo(char const*, char const*, addrinfo const&, addrinfo**, boost::system::error_code&)': /home/ha/MIH/boost_1_49_0/boost/asio/detail/impl/socket_ops.ipp:2899: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking collect2: ld returned 1 exit status

"g++"    -o "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/lte_sim" -Wl,--start-group "../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/Simulator_main.o" "/home/ha/MIH/boost_1_49_0/bin.v2/libs/program_options/build/gcc-4.6/debug/link-static/runtime-link-static/libboost_program_options.a"      -Wl,--end-group -g -static -lboost_system

...failed gcc.link ../../bin.v2/app/lte_sim/gcc-4.6/debug/link-static/runtime-link-static/lte_sim... ...skipped lte_sim for lack of lte_sim... ...failed updating 1 target... ...skipped 1 target...

So any suggestions?

IoT
  • 607
  • 1
  • 11
  • 23
  • 1
    link with Booost.System: `-lboost_system` – Igor R. Feb 27 '14 at 15:47
  • It didn't work too, I tried b2 linkflags=-lboost_system toolset=gcc, I got the above new errors – IoT Feb 27 '14 at 18:03
  • "cannot find -lboost_system" means you probably didn't build Boost.System, or it has some tagged name. Figure out how it's named and where it is, and link with it. – Igor R. Feb 27 '14 at 18:33
  • Thanks for your reply. I tried to use directly the compiler as following: g++ -o test Simulator_main.cpp -I /home/ha/MIH/boost_1_49_0/ -L /usr/local/lib/ -lboost_system -lpthread -lboost_thread It compiled correctly, but when I run the program I get the following errors ./test: error while loading shared libraries: libboost_system.so.1.49.0: cannot open shared object file: No such file or directory I tried to use "-static" but the compilation didn't work. So what can I do? – IoT Feb 27 '14 at 19:41
  • You compile with boost located in `/home/ha/MIH/boost_1_49_0/`, but link with the one located in `/usr/local/lib/`. Are you this particular build is installed there? The better way would be to build boost like this: `./b2 threading=multi link=static stage`, then pass the following path to the linker: -L/home/ha/MIH/boost_1_49_0/stage/lib` – Igor R. Feb 27 '14 at 20:36
  • Yes, I am linking with "/usr/local/lib/" because the Boost libraries exist there, whereas inside /home/ha/MIH/boost_1_49_0/ I don't have the stage/lib. So isn't correct to do what I am doing? – IoT Feb 27 '14 at 20:45
  • Hi Igor R, thanks a lot your method and suggestion worked perfectly. And my program is working perfectly. But can you please elaborate more, what's the difference now from what I was doing before? And why did you use threading=multi? – IoT Feb 27 '14 at 21:54
  • AFAICS, [threading=multi](http://stackoverflow.com/questions/20859761/what-exactly-does-threading-multi-do-when-compiling-boost/20991739#20991739) is not the key point here. I guess the problem was that you mixed different Boost versions, or at least differently configured builds. – Igor R. Feb 28 '14 at 15:39

0 Answers0