Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost with Cmake on linux(ubuntu)

This my CMakeLists.txt file:

add_definitions(-std=c++11)
find_package(Boost 1.55.0 COMPONENTS filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(bst main.cpp)
target_link_libraries(bst ${Boost_LIBRARIES})

When i execute cmake .. in my build directory , cmake successfully generates files .

But when i run make in build directory i get following errors :

amin@aminux:~/Documents/boost_test/build$ make
Scanning dependencies of target bst
[100%] Building CXX object CMakeFiles/bst.dir/main.cpp.o
Linking CXX executable bst
/usr/bin/ld: CMakeFiles/bst.dir/main.cpp.o: undefined reference to    symbol '_ZN5boost6system15system_categoryEv'
//usr/lib/x86_64-linux-gnu/libboost_system.so.1.55.0: error   adding       symbols: DSO missing from command line
 collect2: error: ld returned 1 exit status
make[2]: *** [bst] Error 1
make[1]: *** [CMakeFiles/bst.dir/all] Error 2
make: *** [all] Error 2

in my main.cpp source file i just called boost::filesystem::is_directory function for testing boost .

like image 265
amin Avatar asked Mar 13 '14 08:03

amin


People also ask

Where do I put CMake boost?

Install Boost (Windows) Extract in a Boost folder located at C:\ or C:\Program files so that CMake find-modules can detect it. Invoke the command line and navigate to the extracted folder (e.g. cd C:\Boost\boost_1_63_0 ).

How do you add a boost to Cmakelist?

For CMake, you need to add boost_program_options to the list of libraries, and IIRC this is done via SET(liblist boost_program_options) in your CMakeLists. txt .

What is Boost_INCLUDE_DIRS?

Boost_INCLUDE_DIRS is the list of include directories needed to use Boost. This should include any directories to dependencies needed.


1 Answers

You also should add boost::system library component in your CMakeLists.txt file

find_package(Boost 1.55.0 COMPONENTS filesystem system REQUIRED)

like image 153
Sergei Nikulov Avatar answered Oct 21 '22 06:10

Sergei Nikulov