Windows build 18362
CLion 2019.1.2
Boost 1.67
Toolchain mingw-64
我正在尝试使用Boost在Clion中设置一个简单的项目。问题是,当我包含boost头文件#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的新手,我可能错过了一些非常基础的东西,但我看不出来。有什么线索吗?
发布于 2019-05-02 22:15:54
在从命令行运行后,我得出的结论是这是一个CLion错误。如果包含目录不包含驱动器名称(即C:/
),则CLion找不到头文件。
下面是一个适用于CLion的CMakeLists.txt
:
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()
同样的文件可以从命令行运行,而不需要在include_directories
中添加繁琐的C:
。
请注意,即使没有C:
,CLion也可以很好地构建和运行代码。因此,问题似乎只是基于include_directories()
查找头文件的问题。
发布于 2019-11-19 21:01:15
我刚刚在Ubuntu上试过了,不需要任何破解来让它工作。
find_package(Boost 1.40 COMPONENTS system filesystem program_options log REQUIRED) include_directories(${Boost_INCLUDE_DIRS})
我不确定它是否会有帮助,但至少它在某些方面是有效的。
https://stackoverflow.com/questions/55938632
复制相似问题