0

I am new to c++ and I am using CLion on a Mac. I would like to use the boost 1.65.0 filesystem library. When I add the following import statement the console app doesn't compile.

#include <boost/filesystem.hpp>

I get the following error:

Undefined symbols for architecture x86_64:
  "boost::system::system_category()", referenced from:
      ___cxx_global_var_init.2 in main.cpp.o
  "boost::system::generic_category()", referenced from:
      boost::system::error_category::std_category::equivalent(int, std::__1::error_condition const&) const in main.cpp.o
      boost::system::error_category::std_category::equivalent(std::__1::error_code const&, int) const in main.cpp.o
      ___cxx_global_var_init in main.cpp.o
      ___cxx_global_var_init.1 in main.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [sandbox] Error 1
make[2]: *** [CMakeFiles/sandbox.dir/all] Error 2
make[1]: *** [CMakeFiles/sandbox.dir/rule] Error 2
make: *** [sandbox] Error 2

CMake file:

cmake_minimum_required(VERSION 3.8)
project(sandbox)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES src/main.cpp)

find_package(Boost)
if (Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIR})
endif()

add_executable(sandbox ${SOURCE_FILES})
target_link_libraries (sandbox ${Boost_LIBRARIES})

Other libraries such as the boost string library works fine. But I cant use the filesystem library. Any idea what I am doing wrong?

Dblock247
  • 6,167
  • 10
  • 44
  • 66
  • You need to tell the find_package call what components of Boost to use. Otherwise you can only make use of header only libraries. `find_package(Boost COMPONENTS system filesystem REQUIRED)` should do the trick. And you should use `Boost_INCLUDE_DIRS` variable (note the S at the end). – vre Sep 07 '17 at 06:09
  • And because it seems you are using CMake 3.8 you need to set `set(Boost_ADDITIONAL_VERSIONS "1.65" "1.65.0")` before your find_package call. See the comments section from this question https://stackoverflow.com/questions/46038371/visual-studio-2017-compatibality-with-boost-1-64-0-1-63-0-issue – vre Sep 07 '17 at 06:31
  • @vre Thank you I managed to get it working with some slight differences however I get the following warning Imported targets not available for Boost version 106500. Is there a way to correct this? – Dblock247 Sep 08 '17 at 02:55
  • @Dblock247, unfortunately, no. Boost finder has a hardcoded list of dependencies for every particular known release of boost. 1.65 appeared just recently and finder just have no deps for it hardcoded yet (write a bug report, wait for next release). This list used to make imported targets... – zaufi Sep 08 '17 at 03:17
  • Possible duplicate of [undefined reference to boost::system::system\_category() when compiling](https://stackoverflow.com/questions/9723793/undefined-reference-to-boostsystemsystem-category-when-compiling) – JaMiT Jun 02 '19 at 01:50

0 Answers0