boostcmakeboost-asio

Using boost.asio in CMake


I am relatively new to CMake, and I'm trying use the boost asio library in my project.

I was able to get CMake to find other boost libraries such as smart_ptr and lexical_cast, but I get a linker error when I try to include boost/asio.hpp:

LINK : fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-1_40.lib'.  

I then tried to change my CMakeLists.txt from

find_package(Boost 1.40.0 REQUIRED)

to

find_package(Boost 1.40.0 REQUIRED COMPONENTS asio)

CMake then asks for Boost_ASIO_LIBRARY_DEBUG and Boost_ASIO_LIBRARY_RELEASE. Am I going about this the right way, and if so where should I point CMake to find these libraries. (I am using CMake 2.6 and boost 1.40.0)


Solution

  • According to the ASIO documentation:

    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.

    If you look at your link error, you will see that it is looking for the Boost.System library. I would try changing your CMakLists.txt to read:

    find_package(Boost 1.40.0 REQUIRED system)