我使用以下命令在Ubunto 18.04上安装了Boost:
sudo apt-get libboost-all-dev
仅标头库工作正常,但是当我尝试使用二进制库时,得到以下信息:
/tmp/ccN8OEEH.o: In function `__static_initialization_and_destruction_0(int, int)':
/usr/include/boost/system/error_code.hpp:206: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:208: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:210: undefined reference to `boost::system::system_category()'
/tmp/ccN8OEEH.o: In function `boost::system::error_category::std_category::equivalent(int, std::error_condition const&) const':
/usr/include/boost/system/error_code.hpp:656: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:659: undefined reference to `boost::system::generic_category()'
/tmp/ccN8OEEH.o: In function `boost::system::error_category::std_category::equivalent(std::error_code const&, int) const':
/usr/include/boost/system/error_code.hpp:686: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:689: undefined reference to `boost::system::generic_category()'
/usr/include/boost/system/error_code.hpp:701: undefined reference to `boost::system::generic_category()'
collect2: error: ld returned 1 exit status
The terminal process terminated with exit code: 1
我一直在寻找堆栈溢出的问题,但是列出的解决方案都不适合我。
我的main.cpp看起来像这样(只是想测试boost二进制文件是否起作用):
#include <iostream>
#include <boost/filesystem/path.hpp>
int main() {
return 0;
}
和我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.0.0)
project(f VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(Boost 1.65.1 REQUIRED COMPONENTS filesystem system iostreams)
add_executable(f main.cpp)
target_link_libraries(f Boost::system Boost::filesystem Boost::iostreams)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
我不能完全确定我的boost安装是否正确(它看起来不完全像boost.org上显示的那样)。在usr / lib / x86_64-linux-gnu中,我的苍蝇像:libbost_context.a libboost_context.so libbost_context.so.1.65.1 ...在usr / include / boost中,我有类似的东西:align.hpp asio.hpp assert .hpp ...
那么有谁知道该怎么做才能解决此问题?