I've tried including boost into a cmake project of mine, and I'm having some difficulty getting the project to compile. Specifically, I would like to use things defined in the boost/filesystem.hpp
header.
I've installed boost using apt install libboost-all-dev
, and I've tried making the necessary adjustments to the cmake files in the necessary places, recommended by a few posts from this website. However, the following CMakeLists.txt
file is not working for me (there are a few, but this is the only one that should reference the new boost headers and libraries):
project(run_backtest)
add_subdirectory(markets)
set(SOURCE_FILES main.cpp)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.65.1 COMPONENTS system filesystem)
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${Boost_INCLUDE_DIRS})
link_directories( ${Boost_LIBRARIES})
find_library(mysqlcppconn 1.1.12 REQUIRED)
add_executable(run_backtest ${SOURCE_FILES})
target_link_libraries(run_backtest markets Eigen3::Eigen stdc++fs mysqlcppconn ${Boost_LIBRARIES})
install(TARGETS run_backtest DESTINATION ${MARKETS_INSTALL_BIN_DIR})
I navigate to a directory called ~/markets/build/manual
and type in cmake ../..
. That looks like it works; it prints this out:
taylor@taylor-XPS-13-9365:~/markets/build/manual$ cmake ../..
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- system
-- filesystem
/usr/lib/x86_64-linux-gnu/libboost_system.so/usr/lib/x86_64-linux-gnu/libboost_filesystem.so
-- Configuring done
-- Generating done
-- Build files have been written to: /home/taylor/markets/build/manual
Then make && make install
results in some undefined reference to
errors. Here's the first one copy/pasted:
../src/markets/libmarkets.a(data_readers.cpp.o): In function `number_of_files_in_directory(boost::filesystem::path)':
data_readers.cpp:(.text+0x28b): undefined reference to `boost::filesystem::detail::directory_iterator_construct(boost::filesystem::directory_iterator&, boost::filesystem::path const&, boost::system::error_code*)'
The top of the data_readers.h
file looks like this:
.
.
.
#include <string>
#include <vector>
#include <queue>
#include <boost/filesystem.hpp>
.
.
.
Looking at the cmake docs, I've noticed there are a tremendous amount of variables that give the library directory. Perhaps I'm using the worng one?