1

I'm trying to build Boost's example of an asynchronous TCP daytime server found on this link: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html

Here what I am trying to build the example with:

g++ -o server server.cpp -I ~/boost/include -L~/boost/lib -lboost_system

Here are the errors I am getting:

 g++ -o server server.cpp -I ~/boost/include -L~/boost/lib -lboost_system
/tmp/ccF38gvh.o: In function `__static_initialization_and_destruction_0(int, int)':
server.cpp:(.text+0x221): undefined reference to `boost::system::generic_category()'
server.cpp:(.text+0x22d): undefined reference to `boost::system::generic_category()'
server.cpp:(.text+0x239): undefined reference to `boost::system::system_category()'
/tmp/ccF38gvh.o: In function `boost::system::error_code::error_code()':
server.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/ccF38gvh.o: In function `boost::asio::error::get_system_category()':
server.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[boost::asio::error::get_system_category()]+0x5): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [all] Error 1

What do I need to add to get this to successfully build?

hededo
  • 371
  • 2
  • 16

1 Answers1

2

I'm pretty sure your command line is different.

In particular, could it be you have the source listed /after/ the libs?

Specificly

g++ -o server -I "$HOME/boost/include" -L"$HOME/boost/lib" -lboost_system server.cpp 

would not work, and

g++ -o server server.cpp -I "$HOME/boost/include" -L"$HOME/boost/lib" -lboost_system

should work.

Other than that, see also c++ files to include for boost : asio. The jam-file for the tutorials build everything with -lboost_system -lboost_thread -DBOOST_ALL_NO_LIB=1 (which is likely overkill)

Update Also found this How to compile boost async_client.cpp

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • I moved the position of "server.cpp" and it still isn't working. I will look at the link you have provided. Thanks – hededo Apr 06 '14 at 23:51
  • I have tried using: g++ -o server -I ~/boost/include -L~/boost/lib -lboost_system -lboost_thread -DBOOST_ALL_NO_LIB=1 server.cpp And I have gotten a different error now: /usr/bin/ld: warning: libboost_system.so.1.53.0, needed by /usr/local/lib/libboost_thread.so, may conflict with libboost_system.so.5 – hededo Apr 07 '14 at 00:00
  • That's **not** an error. Just make sure your LD_LIBRARY_PATH finds the required version at runtime. You can also look at the `-Wl,rpath` option. (The linker is warning you that your system LD_LIBRARY_PATH contains a conflicting verion of the same library) – sehe Apr 07 '14 at 00:01
  • so I can use the (-Wl, rpath) option to specify which version I want? – hededo Apr 07 '14 at 00:09
  • You can use it to avoid having to override the LD_LIBRARY_PATH manually. Of course, baking it into the binary is somewhat limited (especially since if it refers to a machine specific path). Just giving you the options – sehe Apr 07 '14 at 00:13
  • I just found another old answer that shows the `-Wl,-rpath` approach (something tells me SO search is not that useless after all) – sehe Apr 07 '14 at 00:20