【发布时间】:2018-11-24 10:07:37
【问题描述】:
我首先说这不是环境变量的问题。
当我使用仅标头库时,一切正常:
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(TestCMake Program.cpp)
target_link_libraries(TestCMake ${Boost_LIBRARIES})
endif()
但是当我尝试通过将 find_package(Boost REQUIRED) 更改为 find_package(Boost REQUIRED COMPONENTS system) 来要求一个库时,我收到一个错误:
Unable to find the requested Boost libraries.
Boost version: 1.67.0
Boost include path: D:/boost/boost_1_67_0
Could not find the following Boost libraries:
boost_system
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the
directory containing Boost libraries or BOOST_ROOT to the location of
Boost.
This answer 在另一个问题上表明 CMake 期望 Boost 二进制文件以某种方式命名:
boost_thread-vc100-mt-1_51
boost_thread-vc100-mt
boost_thread-mt-1_51
boost_thread-mt
boost_thread
我有一个名为boost_system-vc141-mt-x32-1_67.lib 的预编译二进制文件(从here 获得)。 如何让 CMake 识别我的二进制文件中使用的命名约定?
this downvoted answer 对其他问题的评论建议不要重命名文件。
【问题讨论】:
-
您使用的是哪个 CMake 版本?只有在 3.11 之后,CMake 才支持新的 Boost 命名约定。您还可以在项目中使用更新的 FindBoost,它也可以。无需重命名。
-
哇哦,我实际上使用的是 3.10。我现在已经为此浪费了 2 个多小时而感到非常愚蠢。