当我尝试编译使用 boost 和 asio 的 cmake 项目时,make
我收到这些错误:
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()'
我推测找不到 asio 库。所以我将这一行添加到我的根 CMakeLists.txt 中:
find_package(Boost 1.54.0 REQUIRED)
并且 CMake 可以找到所有相关的库,如构建日志的这部分所示:
-- Found the following Boost libraries:
-- unit_test_framework
-- system
-- regex
-- date_time
-- thread
-- filesystem
-- program_options
-- chrono
-- atomic
但编译仍然会产生列出的第一个错误。当我将该 CMake 行更改为:
find_package(Boost 1.54.0 REQUIRED asio)
我从 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
正如你所看到的,我已经安装了所有 Boost 库,但我不明白为什么它找不到 asio。