mercredi 6 septembre 2017

C++ Boost filesystem library compilation error

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?

Aucun commentaire:

Enregistrer un commentaire