CLion 中 CMake 的参考提升

Reference boost from CMake in CLion

CLion 1.2,捆绑了 CMake 3.3.2 和 MinGW-w64 4.8.4 我正在尝试在 CMakeLists.txt

中引用 boost
set(BOOST_ROOT "O:/Project/lib/windows/boost_1_59_0")
set(BOOST_LIBRARYDIR ${BOOST_ROOT}/stage/lib)

set(BOOST_COMPONENTS_NEEDED filesystem )
find_package(Boost 1.59.0 REQUIRED COMPONENTS ${BOOST_COMPONENTS_NEEDED})

if(NOT Boost_FOUND)
  message(FATAL_ERROR "Could not find boost!")
endif()

如果不需要库,我就用

 find_package(Boost 1.59.0)

已找到增强功能并且一切正常。

但是当我尝试引用库时 "Boost_FOUND" 未设置

Boost 库已构建,O:/Project/lib/windows/boost_1_59_0/stage/lib 文件夹中有以下文件

    boost_filesystem-vc120-mt-1_59.dll
    boost_filesystem-vc120-mt-1_59.lib
    boost_filesystem-vc120-mt-gd-1_59.dll
    boost_filesystem-vc120-mt-gd-1_59.lib
    boost_system-vc120-mt-1_59.dll
    boost_system-vc120-mt-1_59.lib
    boost_system-vc120-mt-gd-1_59.dll
    boost_system-vc120-mt-gd-1_59.lib
    libboost_filesystem-vc120-mt-1_59.lib
    libboost_filesystem-vc120-mt-gd-1_59.lib
    libboost_filesystem-vc120-mt-s-1_59.lib
    libboost_filesystem-vc120-mt-sgd-1_59.lib
    libboost_filesystem-vc120-s-1_59.lib
    libboost_filesystem-vc120-sgd-1_59.lib
    libboost_system-vc120-mt-1_59.lib
    libboost_system-vc120-mt-gd-1_59.lib
    libboost_system-vc120-mt-s-1_59.lib
    libboost_system-vc120-mt-sgd-1_59.lib
    libboost_system-vc120-s-1_59.lib
    libboost_system-vc120-sgd-1_59.lib

我错过了什么?

可能是因为您想使用 MinGW 构建您的项目,但是您的库是为 Visual studio 编译的(您可以从库名称中的 vc120 中看到它)。

您必须使用 MinGW-64 构建 boost(您可以使用相同的 stage/lib 文件夹,因为名称不同)。

打开 MinGW 控制台并按照与 Visual Studio 相同的编译步骤进行操作,但将工具集从 msvc 更改为 gcc