Cmake 找不到 Boost [英] Cmake doesn't find Boost
问题描述
我正在尝试使用 CMake 配置一个项目,但它无法找到 Boost 库,即使它们位于指定的文件夹中.我已经指定了 Boost_INCLUDE_DIR
、Boost_LIBRARYDIR
和 BOOST_ROOT
,但我仍然收到错误消息,指出 CMake 无法找到 Boost.出现这种错误的原因可能是什么?
I'm trying to configure a project using CMake, but it fails to find Boost libraries even though they are in the specified folder. I have specified Boost_INCLUDE_DIR
, Boost_LIBRARYDIR
and BOOST_ROOT
, but I still get an error saying that CMake is not able to find Boost. What could be the reason of such error?
推荐答案
你确定你做的方法正确吗?这个想法是 CMake 自动设置 BOOST_INCLUDE_DIR
、BOOST_LIBRARYDIR
和 BOOST_ROOT
.在 CMakeLists.txt
中做这样的事情:
Are you sure you are doing it the correct way? The idea is that CMake sets BOOST_INCLUDE_DIR
, BOOST_LIBRARYDIR
and BOOST_ROOT
automatically. Do something like this in CMakeLists.txt
:
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
如果 boost 没有安装在默认位置并且不能被 CMake 找到,你可以告诉 CMake 在哪里寻找 boost,如下所示:
If boost is not installed in a default location and can, thus, not be found by CMake, you can tell CMake where to look for boost like this:
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")
当然,这两行必须在CMakeLists.txt
中的FIND_PACKAGE(Boost)
之前.
Of course, those two lines have to be before the FIND_PACKAGE(Boost)
in CMakeLists.txt
.
这篇关于Cmake 找不到 Boost的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!