I have a very simple example program that I am trying to compile, but I’m getting linking errors.
Program
int main()
{
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
t.wait();
std::cout << "Hello, world!\n";
return 0;
}
Compilation
I’m using the following compile options:
g++ -L/usr/lib -lboost_system -lboost_filesystem -lboost_thread -pthread -I/usr/include timer.cpp -o timer
Output
I’ve checked that the dynamic libraries exist and are located in the -L path. Here are the errors I’m getting:
/tmp/cc3hJrVk.o: In function `__static_initialization_and_destruction_0(int, int)':
timer.cpp:(.text+0xf0): undefined reference to `boost::system::generic_category()'
timer.cpp:(.text+0xfc): undefined reference to `boost::system::generic_category()'
timer.cpp:(.text+0x108): undefined reference to `boost::system::system_category()'
/tmp/cc3hJrVk.o: In function `boost::system::error_code::error_code()':
timer.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/cc3hJrVk.o: In function `boost::asio::error::get_system_category()':
timer.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
As you can see, it seems like the bugs are something you’d get if you’re improperly linking to libboost_system. I have two separate installs of boost that I’ve tested against, and I’m at my wit’s end.
Thanks in advance for any help!
You need to move all your libraries after the file names, at the end of the command.
Also: Boost::System must be built separately from the normal boost libraries. So if you haven’t built them separately they won’t exist.
See section 3 here:
http://www.boost.org/doc/libs/1_49_0/more/getting_started/unix-variants.html