问题描述
我希望在我的项目中使用boost.asio头文件,但当我包含它的.hpp文件时,我在编译时收到以下输出错误:
我需要为CROW发送我的Web请求的bost.asio。
/home/john/Downloads/clion-1.2.4/bin/cmake/bin/cmake--构建/home/john/.CLion12/system/cmake/generated/a3f08900/a3f08900/Release--目标Rcp-j8[50%]链接Cxx可执行/home/john/projects/rightChoiceProperty/bin/rcpCMakeFiles/rcp.dir/main.cpp.o:in函数
_GLOBAL__sub_I_main':main.cpp:(.text.startup+0x53): undefined reference to
Boost::System::Generic_Category()‘Main.cpp:(.ext.startup+0x58):对boost::system::generic_category()'main.cpp:(.text.startup+0x5d): undefined reference to
Boost::System::System_Category()‘的引用未定义Main.cpp:(.ext.startup+0x62):未定义对`Boost::System::System_Category()‘的引用Collect2:错误:LD返回%1退出状态CMakeFiles/rcp.dir/Build.make:94:目标‘/home/john/projects/rightChoiceProperty/bin/rcp’的配方失败Make[3]:*[/home/john/projects/rightChoiceProperty/bin/rcp]错误1CMakeFiles/MakeFile2:67:目标‘CMakeFiles/rcp.dir/all’的配方失败Make[2]:[CMakeFiles/rcp.dir/all]错误2CMakeFiles/MakeFile2:79:目标‘CMakeFiles/rcp.dir/Rule’的配方失败Make[1]:[CMakeFiles/rcp.dir/Rule]错误2Makefile:118:目标‘rcp’的配方失败生成:*[RCP]错误2
#include <iostream>
#include <boost/asio.hpp>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
这是我的CMakeLists.txt文件内容:
cmake_minimum_required(VERSION 3.3)
project(rcp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lboost_system")
set(SOURCE_FILES main.cpp)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
include_directories("libraries/boost")
add_executable(rcp ${SOURCE_FILES})
非常感谢
推荐答案
-l
选项不是编译器选项,而是链接器选项,因此您为错误的变量设置了它,因为CMAKE_CXX_FLAGS
仅用于编译器。
target_link_libraries
来添加库。如target_link_libraries(rcp boost_system)
但您真正应该做的是找到系统安装的Boost库并使用它们。您可以使用find_package
:
find_package(Boost
REQUIRED COMPONENTS asio system)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(rcp ${Boost_LIBRARIES})
这篇关于添加Boost/ASIO时未定义对`Boost::System::Generic_Category()';的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!