Michael Josephson
Michael Josephson

Reputation: 228

CLion not finding Boost headers

Windows build 18362
CLion 2019.1.2
Boost 1.67
Toolchain mingw-64

I'm trying to setup a simple project in Clion using Boost. The problem is when I include a boost header #include <boost/log/trivial.hpp>, CLion cannot find the header file.

My 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})

The output of CMake seems to indicate that everything is found correctly:

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

But still CLion cannot find the header file in the include statement. The header files are indeed present at the location specified in Boost_INCLUDE_DIR. I'm new to Windows and CLion , and I probably missing some really basic, but I cannot see it. Any clues?

Upvotes: 0

Views: 1104

Answers (2)

J. Bailleul
J. Bailleul

Reputation: 53

I just tried doing this from Ubuntu, and no need for any hack to get this working.

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

Not sure it may help, but at least it works somewhere.

Upvotes: 0

Michael Josephson
Michael Josephson

Reputation: 228

After getting this to work from the command line, I've come to the conclusion that is a CLion bug. If the include directory does not include the drive designation (i.e., C:/), CLion is not finding the header files.

Here is a CMakeLists.txt that works for 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()

This same file works from the command line without the hacky C: added to the include_directories.

Note that even without the C:, CLion will build and run the code just fine. So the issue seems to be solely with finding the header files based on include_directories().

Upvotes: 0

Related Questions