CLion未找到Boost标头

时间:2019-05-01 15:24:45

标签: boost clion

Windows build 18362
CLion 2019.1.2
Boost 1.67
Toolchain mingw-64

我正在尝试使用Boost在Clion中设置一个简单的项目。问题是当我包含增强头文件#include <boost/log/trivial.hpp>时,CLion无法找到头文件。

我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
project(BoostTest)

set(CMAKE_CXX_STANDARD 14)

add_executable(BoostTest main.cpp)

set(BOOST_ROOT "$ENV{HOMEPATH}/.local/share/boost")
set(Boost_ARCHITECTURE "-x64")
find_package(Boost REQUIRED COMPONENTS log)
message(STATUS "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}")
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries(BoostTest ${Boost_LIBRARIES})

CMake的输出似乎表明已正确找到所有内容:

C:\Users\michael\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\191.6707.69\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\michael\projects\sml\BoostTest
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/mingw/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/mingw/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/mingw/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/mingw/mingw64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Boost version: 1.67.0
-- Found the following Boost libraries:
--   log
--   date_time
--   log_setup
--   system
--   filesystem
--   thread
--   regex
--   chrono
--   atomic
-- Boost_INCLUDE_DIR: /Users/michael/.local/share/boost/include/boost-1_67
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/michael/projects/sml/BoostTest/cmake-build-debug

但是,CLion仍然无法在include语句中找到头文件。头文件确实存在于Boost_INCLUDE_DIR中指定的位置。我是Windows和CLion的新手,我可能缺少一些基本知识,但我看不到。有任何线索吗?

2 个答案:

答案 0 :(得分:0)

在命令行中完成此操作后,我得出的结论是CLion错误。如果include目录中不包含驱动器名称(即C:/),则CLion找不到头文件。

这是CMakeLists.txt,适用于CLion:

cmake_minimum_required(VERSION 3.14)
project(boost-test)

set(CMAKE_CXX_STANDARD 14)
add_executable(boost-test main.cpp)

set(Boost_USE_STATIC_LIBS   ON)
find_package(Boost REQUIRED COMPONENTS log)
if (Boost_FOUND)
    message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
    include_directories("C:${Boost_INCLUDE_DIRS}")
    target_link_libraries(boost-test ${Boost_LIBRARIES})
endif()

同一文件可从命令行使用,而没有将C:添加到include_directories中。

请注意,即使没有C:,CLion也会很好地构建和运行代码。因此,问题似乎完全在于基于include_directories()查找头文件。

答案 1 :(得分:0)

我只是尝试从Ubuntu上进行此操作,不需要任何黑客工具即可使它工作。

find_package(Boost 1.40 COMPONENTS system filesystem program_options log REQUIRED) include_directories(${Boost_INCLUDE_DIRS})

不确定是否有帮助,但至少在某些地方可以使用。