Reputation: 9183
My IDE is Clion, but I think it doesn't matter since it uses CMakeLists.txt.
Here is my main.cpp in which I include boost filesystem.hpp:
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(AsioFirst)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories("/usr/local/src/boost_1_60_0/boost_1_60_0/")
link_directories("/usr/local/src/boost_1_60_0/boost_1_60_0/stage/lib")
set(SOURCE_FILES main.cpp)
add_executable(AsioFirst ${SOURCE_FILES})
But when I run that (using arguments -lboost_system -lboost_filesystem
), I get the following error which is probably a linking error:
boost::system::generic_category()
Directories are double checked, and they are correct.
Upvotes: 0
Views: 88
Reputation: 914
Do not hardcode your dependencies/library paths. Better use find_package command to find Boosts include directories and libraries:
cmake_minimum_required(VERSION 3.2)
project(AsioFirst)
#Add a hint about your boost copy
set(BOOST_ROOT "/usr/local/src/boost_1_60_0/boost_1_60_0/")
find_package(Boost REQUIRED COMPONENTS filesystem system)
set(SOURCE_FILES main.cpp)
add_executable(AsioFirst ${SOURCE_FILES})
#More portable than setting CMAKE_CXX_FLAGS
set_property(TARGET AsioFirst PROPERTY CXX_STANDARD 11)
target_include_directories(AsioFirst PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(AsioFirst PRIVATE ${Boost_LIBRARIES})
Upvotes: 2
Reputation: 9183
I post this for future visitors: The solution was that I should have added the exact link to the libraries used:
link_libraries("/usr/local/src/boost_1_60_0/boost_1_60_0/stage/lib/libboost_system.so")
link_libraries("/usr/local/src/boost_1_60_0/boost_1_60_0/stage/lib/libboost_filesystem.so")
It seems the arguments lboost_system -lboost_filesystem
did not resolve the linking.
Upvotes: -1