简体   繁体   中英

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

I have problems with 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. 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

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.

All non-header-only libraries from Boost which you use need to be listed explicitly for ${Boost_LIBRARIES} to be populated correctly. 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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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