gpt4 book ai didi

c++ - 使用 CMake 对 boost::iostreams::mapped_file_source::init() 的 undefined reference

转载 作者:行者123 更新时间:2023-11-30 01:08:47 26 4
gpt4 key购买 nike

使用 Boost Iostream 的最小示例的链接错误。看起来我没有与 libboost_iostream 链接,但是 CMake 报告说找到了库,并且其他带有 Boost 的应用程序编译和链接没有任何问题。

使用 Cmake 构建:

cmake_minimum_required(VERSION 3.0)
project(mmap_example CXX)
set(TARGET mmap_example)

set(BOOST_MIN_VERSION "1.61.0")
set(Boost_ADDITIONAL_VERSIONS "1.61.0" "1.61")
set(Boost_USE_STATIC_LIBS ON)
set(BOOST_ROOT ${MY_BOOST_DIR})

find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS iostreams REQUIRED)

set(CMAKE_CXX_FLAGS "-std=c++11 -std=gnu++1y -pthread")
set(CMAKE_EXE_LINKER_FLAGS "-std=c++11 -std=gnu++1y -pthread")

file(GLOB SOURCES *.cpp)

include_directories(${Boost_INCLUDE_DIRS})

add_executable(${TARGET} ${SOURCES})

target_link_libraries(${TARGET} ${Boost_IOSTREAMS})

C++ 本身:

#include <boost/iostreams/device/mapped_file.hpp>

namespace boost_io = boost::iostreams;

int main(int argc, char** argv) {

boost_io::mapped_file_source file(argv[1]);
return 0;
}

海湾合作委员会输出:

Linking CXX executable mmap_example
CMakeFiles/mmap_example.dir/mmap.cpp.o: In function boost::iostreams::mapped_file_source::mapped_file_source<char*>(char* const&, unsigned int, long long):
mmap.cpp:(.text._ZN5boost9iostreams18mapped_file_sourceC2IPcEERKT_jx[_ZN5boost9iostreams18mapped_file_sourceC5IPcEERKT_jx]+0x43): undefined reference to boost::iostreams::mapped_file_source::init()

海湾合作委员会(Debian 4.9.2-10)4.9.2

CMake 3.0.2

提升 1.61

最佳答案

我不确定 ${Boost_IOSTREAMS} 是要使用的正确变量,据我所知,它应该是 ${Boost_LIBRARIES}(至少我总是这样使用)。

你可以通过使用检查变量是否真的被设置

message(STATUS "Boost_IOSTREAMS: ${Boost_IOSTREAMS}")

在你的 cmake 文件中。

你也可以使用

make all VERBOSE=1

列出所有命令,检查链接器命令行上存在哪些库。

关于c++ - 使用 CMake 对 boost::iostreams::mapped_file_source::init() 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41481794/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com