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.
请先登录再写评论。
Here is a Live Template version of the solution.