When I try to compile my cmake project, which uses boost and asio, with make
I get these errors:
CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init1':
/usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()' CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init1':
/usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init2':
/usr/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init3':
/usr/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `__cxx_global_var_init1':
/usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `__cxx_global_var_init2':
/usr/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `__cxx_global_var_init3':
/usr/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `boost::network::uri::uri::parse()':
/home/darren/373project/include/boost/network/uri/uri.hpp:178: undefined reference to `boost::network::uri::detail::parse(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::network::uri::detail::uri_parts<__gnu_cxx::__normal_iterator<char const*, std::string> >&)'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `error_code':
/usr/include/boost/system/error_code.hpp:323: undefined reference to `boost::system::system_category()'
CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init2':
/usr/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `__cxx_global_var_init3':
/usr/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
CMakeFiles/client-network-handler-test.dir/main.cpp.o: In function `boost::asio::error::get_system_category()':
/usr/include/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `__cxx_global_var_init1':
/usr/include/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `__cxx_global_var_init2':
/usr/include/boost/system/error_code.hpp:223: undefined reference to `boost::system::generic_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `__cxx_global_var_init3':
/usr/include/boost/system/error_code.hpp:224: undefined reference to `boost::system::system_category()'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `boost::network::uri::uri::parse()':
/home/myUserName/373project/include/boost/network/uri/uri.hpp:178: undefined reference to `boost::network::uri::detail::parse(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::network::uri::detail::uri_parts<__gnu_cxx::__normal_iterator<char const*, std::string> >&)'
../../lib/libclient-network-handler.a(ClientNetworkHandler.cpp.o): In function `error_code':
/usr/include/boost/system/error_code.hpp:323: undefined reference to `boost::system::system_category()'
I gather that the asio library cannot be found. So I add this line to my root CMakeLists.txt:
find_package(Boost 1.54.0 REQUIRED)
And CMake can find all the relevant libraries, as shown by this part of the build log:
-- Found the following Boost libraries:
-- unit_test_framework
-- system
-- regex
-- date_time
-- thread
-- filesystem
-- program_options
-- chrono
-- atomic
But compilation still produces the first error listed. When I change that CMake line to:
find_package(Boost 1.54.0 REQUIRED asio)
I get this message from CMake:
CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (message):
Unable to find the requested Boost libraries.
Boost version: 1.54.0
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_asio
I have all the Boost libraries installed, as you can see, and I can't understand why it can't find asio.