简体   繁体   English

c ++链接ubuntu下的boost库和cmake:未定义引用`boost :: iostreams :: zlib :: okay'

[英]c++ linking boost library under ubuntu with cmake: undefined reference to `boost::iostreams::zlib::okay'

I have problems with boost::iostreams . 我有boost::iostreams问题。 I want to use them in only one function. 我想只在一个函数中使用它们。 The only problem is with this line: 唯一的问题是这一行:

in.push(boost::iostreams::gzip_decompressor());

Boost is used in other parts of the program without any problems or compile errors. Boost用于程序的其他部分,没有任何问题或编译错误。 However If I use this line I get the compile error: 但是,如果我使用此行,我会收到编译错误:

undefined reference to `boost::iostreams::zlib::okay'

It is included like this: 它包括这样:

#include <boost/iostreams/filter/gzip.hpp>

CMakeLists.txt 的CMakeLists.txt

add_library(backend
    ... some files
)

find_package(Boost COMPONENTS system REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(backend ${Boost_LIBRARIES})

Your find_package call for Boost is incomplete. 您对Boost的find_package调用不完整。

All non-header-only libraries from Boost which you use need to be listed explicitly for ${Boost_LIBRARIES} to be populated correctly. 您使用的所有来自Boost的非标头库都需要明确列出,以便${Boost_LIBRARIES}正确填充。 It is easy to lose track of which parts of Boost are header-only and which are not, but linker errors like the one you encountered are always a clear hint. 很容易忘记Boost的哪些部分只是标题,哪些不是,但是你遇到的链接器错误总是一个明确的暗示。

find_package(Boost REQUIRED COMPONENTS system iostreams)

Also note that you might have to pull in additional dependencies on Linux to get the compression to work, as suggested in the comments . 另请注意,您可能需要在Linux上引入其他依赖项以使压缩工作,如评论中所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM