Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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})
like image 481
Sadik Avatar asked Jul 01 '14 11:07

Sadik


1 Answers

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.

like image 56
ComicSansMS Avatar answered Sep 29 '22 04:09

ComicSansMS