这是我的CMakeList.text:
cmake_minimum_required(VERSION 3.12)
project(project)
set(CMAKE_CXX_STANDARD 14)
FIND_PACKAGE(Boost 1.66 REQUIRED date_time program_options thread filesystem system unit_test_framework)
IF(${Boost_FOUND})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ENDIF()
add_executable(project main.cpp)
target_link_libraries(project ${Boost_LIBRARIES})
它配置良好,并根据输出信息确实找到了提升位置。
但是,当我尝试运行程序时,它显示错误:
gmake[3]: *** No rule to make target '/usr/include/_ansi.h', needed by 'CMakeFiles/project.dir/main.cpp.o'. Stop.
gmake[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/project.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/project.dir/rule] Error 2
gmake: *** [Makefile:118: project] Error 2
其中_ansi.h
是我的/usr/include/
中的第一个头文件,boost也位于/usr/include/boost
中。我已检查该文件确实存在,如果删除了该文件,它将显示no rule to make target on {the second header file}
。
任何想法如何解决?
答案 0 :(得分:0)
此摘录直接来自official documentation:
find_package(Boost 1.66 REQUIRED COMPONENTS date_time program_options thread filesystem system unit_test_framework)
if (Boost_FOUND)
add_executable(pro main.cpp)
target_link_libraries(pro Boost::date_time Boost::program_options Boost::thread Boost::filesystem Boost::system Boost::unit_test_framework)
endif()