c ++将ubuntu下的boost库与cmake:undefined引用连接到`boost :: iostreams :: zlib :: okay'

时间:2014-07-01 11:39:04

标签: c++ boost cmake gzip

我遇到boost::iostreams的问题。我想只在一个函数中使用它们。 唯一的问题是这一行:

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

Boost在程序的其他部分使用,没有任何问题或编译错误。 但是,如果我使用这一行,我会收到编译错误:

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

它包括在内:

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

的CMakeLists.txt

add_library(backend
    ... some files
)

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

1 个答案:

答案 0 :(得分:8)

find_package对Boost的调用不完整。

您使用的Boost中所有非标头库都需要明确列出才能正确填充${Boost_LIBRARIES}。很容易忘记Boost的哪些部分只是标题,哪些不是,但是你遇到的链接器错误总是一个明确的暗示。

find_package(Boost REQUIRED COMPONENTS system iostreams)

另请注意,您可能需要在Linux上引入其他依赖项以使压缩工作,suggested in the comments

相关问题