我一直在尝试使用cmake将Boost安装到我的CLion IDE上。我手动设置了Boost CMake变量,如下所示:
set(Boost_INCLUDE_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0)
set(Boost_LIBRARY_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0/libs)
不会弹出任何错误。但这里的警告是:
WARNING: Target "BoostTest" requests linking to directory "C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0/libs". Targets may link only to libraries. CMake is dropping the item.
阻止我在我的CLion文件中使用Boost。
这里是我完整的cmakelists.txt文件,我想我不应该手动指定Boost变量,但我正急于使用它。
cmake_minimum_required(VERSION 3.17)
project(Lantern)
set(CMAKE_CXX_STANDARD 17)
add_executable(Lantern
BattleManager.h
CharacterComponents.h
CMain.c++
CTests.cpp
CTree.h
GameCharacters.h
GameCommands.h
GameStructure_main.h
GameUtilities.h CPlayGround.cpp CPlayGround.h)
set(Boost_INCLUDE_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0)
set(Boost_LIBRARY_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0/libs)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(BoostTest CPlayGround.cpp)
target_link_libraries(BoostTest ${Boost_LIBRARY_DIR})
在这一行中,您告诉CMake将您的可执行目标boosttest
链接到一个目录:
target_link_libraries(BoostTest ${Boost_LIBRARY_DIR})
您要做的是通过查看find_package
,使用findboost
机制:
find_package(Boost REQUIRED <components>)
其中是您需要的Boost库的列表。然后您可以通过执行以下操作将应用程序链接到Boost
target_link_libraries(BoostTest Boost::boost)
并将任何其他非标头Boost库添加到该列表中。上面链接的页面解释了您设置的两个变量用作findboost
脚本的提示(和/或输出)。