Deekor
Deekor

Reputation: 9499

Getting Boost asio to work

I am trying to use the Boost asio library to for sockets.

I installed boost using homebrew brew install boost

After it was built I tried the tutorial for creating a server on boost's website.

All I did was paste that code into a file called main.cc

When I try to compile g++ main.cc I get this error:

Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
  __static_initialization_and_destruction_0(int, int)in ccTbzxpk.o
  boost::asio::error::get_system_category()    in ccTbzxpk.o
  boost::system::error_code::error_code()in ccTbzxpk.o
"boost::system::generic_category()", referenced from:
  __static_initialization_and_destruction_0(int, int)in ccTbzxpk.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

What is going wrong?

Upvotes: 0

Views: 1639

Answers (1)

Jesse Good
Jesse Good

Reputation: 52365

Those are linker errors. If you read the docs:

The following libraries must be available in order to link programs that use Boost.Asio:

Boost.System for the boost::system::error_code and boost::system::system_error classes. Boost.Regex (optional) if you use any of the read_until() or async_read_until() overloads that take a boost::regex parameter. OpenSSL (optional) if you use Boost.Asio's SSL support.

Furthermore, some of the examples also require the Boost.Thread, Boost.Date_Time or Boost.Serialization libraries.

Now, the errors you posted all say: boost::system, this means you need to link like this (assuming everything is the default): g++ main.cc -lboost_system

Please read What do 'statically linked' and 'dynamically linked' mean? for in-depth information about linking.

Upvotes: 3

Related Questions