Skip to content

Instantly share code, notes, and snippets.

@patrickmoffitt
Created October 12, 2017 16:29
Show Gist options
  • Save patrickmoffitt/43f67979953ab5c0174b032b3a5a1b9b to your computer and use it in GitHub Desktop.
Save patrickmoffitt/43f67979953ab5c0174b032b3a5a1b9b to your computer and use it in GitHub Desktop.
Clion 2017.2, CMake 3.9.2 and Boost 1.65.1 on Mac OS X Sierra 10.12.6
If your project uses a Boost library that is not header-only such as
#include "boost/filesystem.hpp"
And, you're getting link errors such as:
Undefined symbols for architecture x86_64:
...
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You need to give your project's CMakeLists.txt the help of CMake's find_package() module.
find_package(Boost 1.65.1 COMPONENTS filesystem REQUIRED)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(10_file_io ${SOURCE_FILES})
target_link_libraries(your_project_name ${Boost_LIBRARIES})
endif()
Note that you're moving the add_executable line into the code block shown above. Replace
filesystem with the name of the Boost library your project requires. Replace
your_project_name with the name of your project.
CLion 2017.2 shipped with CMake 3.8.2 which does not provide CMake find_package() support
for Boost 1.65.1. That's why I'm using an external CMake (version 3.9.2). I installed Boost
and CMake using homebrew.
I spent a lot of time finding this solution after many promising but ultimately useless
web results. This solution appears in ./cmake/3.9.4/share/cmake/Modules/FindBoost.cmake
If you're having Boost library linking issues seek out this file on your own system and
read it. It contains the most up-to-date documentation for find_package().
I hope this helps you.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment