Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 尝试在cmake项目中包含boost后链接错误_C++_Boost_Cmake_Ubuntu 18.04 - Fatal编程技术网

C++ 尝试在cmake项目中包含boost后链接错误

C++ 尝试在cmake项目中包含boost后链接错误,c++,boost,cmake,ubuntu-18.04,C++,Boost,Cmake,Ubuntu 18.04,我已经尝试将boost包含到我的一个cmake项目中,但在编译该项目时遇到了一些困难。具体来说,我想使用boost/filesystem.hpp标题中定义的内容 我已经使用apt install libboost all dev安装了boost,并且我已经尝试在必要的位置对cmake文件进行必要的调整,这是本网站的一些帖子推荐的。但是,以下CMakeLists.txt文件对我不起作用(有一些,但这是唯一一个应该引用新的boost头文件和库的文件): 我导航到一个名为~/markets/build

我已经尝试将boost包含到我的一个cmake项目中,但在编译该项目时遇到了一些困难。具体来说,我想使用
boost/filesystem.hpp
标题中定义的内容

我已经使用apt install libboost all dev安装了boost,并且我已经尝试在必要的位置对cmake文件进行必要的调整,这是本网站的一些帖子推荐的。但是,以下
CMakeLists.txt
文件对我不起作用(有一些,但这是唯一一个应该引用新的boost头文件和库的文件):

我导航到一个名为
~/markets/build/manual
的目录,然后键入
cmake../.
。这看起来是可行的;它打印出来:

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
然后,
make&&makeinstall
会导致一些
引用未定义的
错误。这是第一个复制/粘贴的:

../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*)'
data\u readers.h
文件的顶部如下所示:

.
.
.
#include <string>
#include <vector>
#include <queue>
#include <boost/filesystem.hpp>
.
.
.
。
.
.
#包括
#包括
#包括
#包括
.
.
.

查看,我注意到有大量的变量提供了库目录。也许我使用的是worng one?

这里我对您的CMakeLists.txt进行了一些修改,并添加了一些注释,以便于澄清

project(run_backtest)

add_subdirectory(markets)
set(SOURCE_FILES main.cpp)

# You shouldn't need these, i got my copy working without them 
# set(Boost_USE_STATIC_LIBS OFF) 
# set(Boost_USE_MULTITHREADED ON)  
# set(Boost_USE_STATIC_RUNTIME OFF) 
# Here i added 'Required' so that the build will fail if it cannot find boost
find_package(Boost 1.65.1 REQUIRED COMPONENTS system filesystem) 

find_package (Eigen3 3.3 REQUIRED NO_MODULE)

# You shouldn't have to use find_library, it's a lower level command
# and find_package should encapsulate it's functionality
find_package (mysqlcppconn 1.1.12 REQUIRED)

add_executable(run_backtest ${SOURCE_FILES})

# Here i replaced the variables (e.g ${BOOST_Libraries}) with Boost::system
# This is called an 'alias'. They're added by the Find_Package() call.
target_link_libraries(run_backtest markets
    Eigen3::Eigen
    stdc++fs
    mysqlcppconn
    Boost::system)
install(TARGETS run_backtest DESTINATION ${MARKETS_INSTALL_BIN_DIR})

${Boost\u LIBRARIES}
变量的内容是什么?您是否尝试打印此文件以查看是否实际找到了库?您正在使用
Boost\u库
(库名称列表)作为
link\u目录
。我想你应该在那里使用
Boost\u LIBRARY\u DIRS
。另外,在查找boost时,您应该将
必需的
添加到
查找包
。@squareskittles我添加了
消息(${boost\u LIBRARIES})
,并且我已经将调用
cmake../.
的输出添加到question@VTT还是没有骰子。同样的错误您已经检查了对
boost::filesystem
的未解析引用,是吗?此外,根据错误消息,导致链接器错误的是
libmarkets.a
,它内置于
add\u子目录(市场)
中,没有有效的
find\u包(Boost)
。这不是一个很糟糕的问题-静态库在创建时没有链接-但这闻起来不好。谢谢这非常有用(+1)@Taylor你能让它与我建议的更改一起工作吗?我想到的另一件事是,如果你的编译目标是x64,而你的boost是x32,有时这可能是问题的原因。我能够让它工作,但不是从你的信息。如果这听起来有点意思,那很抱歉,但这是我的错……这个问题是不恰当的,我发布了一个后续问题,为我解决了所有问题。
project(run_backtest)

add_subdirectory(markets)
set(SOURCE_FILES main.cpp)

# You shouldn't need these, i got my copy working without them 
# set(Boost_USE_STATIC_LIBS OFF) 
# set(Boost_USE_MULTITHREADED ON)  
# set(Boost_USE_STATIC_RUNTIME OFF) 
# Here i added 'Required' so that the build will fail if it cannot find boost
find_package(Boost 1.65.1 REQUIRED COMPONENTS system filesystem) 

find_package (Eigen3 3.3 REQUIRED NO_MODULE)

# You shouldn't have to use find_library, it's a lower level command
# and find_package should encapsulate it's functionality
find_package (mysqlcppconn 1.1.12 REQUIRED)

add_executable(run_backtest ${SOURCE_FILES})

# Here i replaced the variables (e.g ${BOOST_Libraries}) with Boost::system
# This is called an 'alias'. They're added by the Find_Package() call.
target_link_libraries(run_backtest markets
    Eigen3::Eigen
    stdc++fs
    mysqlcppconn
    Boost::system)
install(TARGETS run_backtest DESTINATION ${MARKETS_INSTALL_BIN_DIR})