簡體   English   中英

使用CMake對boost :: iostreams :: mapped_file_source :: init()的未定義引用

[英]undefined reference to boost::iostreams::mapped_file_source::init() using CMake

使用Boost Iostreams在最小示例上鏈接錯誤。 看起來我還沒有鏈接到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;
}

GCC輸出:

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()

gcc(Debian 4.9.2-10)4.9.2

的Cmake 3.0.2

提升1.61

我不確定${Boost_IOSTREAMS}是要使用的正確變量,AFAIK應該是${Boost_LIBRARIES} (至少這是我一直使用的變量)。

您可以通過使用以下命令檢查變量是否確實設置

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

在您的cmake文件中。

您也可以使用

make all VERBOSE=1

列出所有命令,檢查鏈接器命令行上存在哪些庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM