c++ - CLion 和 Boost 1.60.0

标签 c++ boost cmake clion

在过去的几天里,我一直在努力让 Boost 库包含在我的项目中。我一直在阅读和使用 Stack Overflow 上众多发帖人提出的建议,出于某种我不明白的原因,我仍然无法让 CMake 找到 Boost,或者如果它确实找到了 Boost,我无法编译,因为它无法找到我显然需要链接的 boost_system 库,以删除系统 config() 未找到错误。

我目前正在使用 GNU C++ 编译器 v4.9.3-1 的 MinGW 实现在 Windows 10 上工作

Boost 目前在我的系统上提取:

C:\boost_1_60_0

这是我的 CMake 文件目前的样子:

cmake_minimum_required(VERSION 3.5)
project(Engine)

#SET(GCC_COVERAGE_LINK_FLAGS "-lboost_system")

message(STATUS "start running cmake...")

SET(BOOSTROOT "C:/boost_1_60_0/")
SET(BOOST_ROOT "C:/boost_1_60_0/")
SET(BOOST_LIBRARYDIR "C:/boost_1_60_0/libs/")

find_package(Boost 1.60.0 COMPONENTS system REQUIRED)

if(Boost_FOUND)

    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
    message(STATUS "Boost_VERSION: ${Boost_VERSION}")

    include_directories(${Boost_INCLUDE_DIRS})
    add_definitions("-DHAS_BOOST")

endif()

add_executable(Engine main.cpp)

if(Boost_FOUND)

    target_link_libraries(Engine ${Boost_LIBRARIES})

endif()

set(SOURCE_FILES main.cpp)

我目前得到的错误是:

Error:Unable to find the requested Boost libraries.
Boost version: 1.60.0
Boost include path: C:/boost_1_60_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.

**更新** 这是使用 -DBoost_Debug=ON 运行 cmake 时的输出:

_boost_TEST_VERSIONS = 1.61.0;1.61;1.60.0;1.60
Boost_USE_MULTITHREADED = TRUE
Boost_USE_STATIC_LIBS = 
Boost_USE_STATIC_RUNTIME = 
Boost_ADDITIONAL_VERSIONS = 
Boost_NO_SYSTEM_PATHS = 
Declared as CMake or Environmental Variables:
 BOOST_ROOT = C:/boost_1_60_0/
 BOOST_INCLUDEDIR = 
 BOOST_LIBRARYDIR = C:/boost_1_60_0/libs/
_boost_TEST_VERSIONS = 1.61.0;1.61;1.60.0;1.60
location of version.hpp: C:/boost_1_60_0/boost/version.hpp
version.hpp reveals boost 1.60.0
guessed _boost_COMPILER = -mgw49
_boost_MULTITHREADED = -mt
_boost_RELEASE_ABI_TAG = -
_boost_DEBUG_ABI_TAG = -d
_boost_LIBRARY_SEARCH_DIRS_RELEASE = C:/boost_1_60_0/libs/;C:/boost_1_60_0//lib;C:/boost_1_60_0//stage/lib;C:/boost_1_60_0/lib;C:/boost_1_60_0/../lib;C:/boost_1_60_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG   = C:/boost_1_60_0/libs/;C:/boost_1_60_0//lib;C:/boost_1_60_0//stage/lib;C:/boost_1_60_0/lib;C:/boost_1_60_0/../lib;C:/boost_1_60_0/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
Searching for SYSTEM_LIBRARY_RELEASE: boost_system-mgw49-mt-1_60;boost_system-mgw49-mt;boost_system-mt-1_60;boost_system-mt;boost_system
Searching for SYSTEM_LIBRARY_DEBUG: boost_system-mgw49-mt-d-1_60;boost_system-mgw49-mt-d;boost_system-mt-d-1_60;boost_system-mt-d;boost_system-mt;boost_system

提前致谢

最佳答案

有一些有用的标志可以帮助 FindBoost 查找库。

在调用 find_package(Boost)

之前尝试设置这些变量(打开或关闭 - 这取决于您的 boost 安装)
set(Boost_LIB_PREFIX            "lib"       CACHE STRING "")
set(Boost_USE_MULTITHREADED     ON          CACHE BOOL "") # '-mt' flag
set(Boost_USE_STATIC_LIBS       ON          CACHE BOOL "")
set(Boost_USE_STATIC_RUNTIME    ON          CACHE BOOL "") # '-s' tag
set(Boost_USE_DEBUG_RUNTIME     ON          CACHE BOOL "") # '-g' tag
set(Boost_COMPILER              "-mgw49"    CACHE STRING "")

使用 set(Boost_DETAILED_FAILURE_MSG TRUE) 设置标志将极大地帮助您进行诊断

关于c++ - CLion 和 Boost 1.60.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36362774/

相关文章:

c++ - 在 C++ 和 C 中的现有选项卡中打开 URL

c++ - 是否可以混淆 RTTI 数据?

c++ - 保存二维 map 的好方法是什么

c++ - cmake的默认构建配置是什么

unit-testing - 如何开始使用 GTest 和 CMake

batch-file - 如何从CMake运行.bat文件?

c++ - 从 recvfrom 获取未记录的错误代码

javascript - 有没有办法将 String 转换为可执行的 C++ 表达式?

c++ - boost::log 关闭日志文件并打开一个新的

c++ - boost::multi_index 随机访问唯一索引