2

I have a piece of C++ software that uses a bzip2 decompressor on a boost::iostreams::filtering_istreambuf. This works well.

I now tried to change it to also support lzma decompression. The corresponding include file seems to be there in my ubuntu 18.04 installation:

$ ls -al /usr/include/boost/iostreams/filter/
-rw-r--r-- 1 root root 13199 Mar  6  2018 bzip2.hpp
-rw-r--r-- 1 root root 24804 Mar  6  2018 gzip.hpp
-rw-r--r-- 1 root root 12157 Mar  6  2018 lzma.hpp
-rw-r--r-- 1 root root 14650 Mar  6  2018 zlib.hpp
(shortened)

However, the code does not link, I get error messages as follows:

In function `boost::iostreams::detail::lzma_decompressor_impl<std::allocator<char> >::lzma_decompressor_impl()':
test2.cpp:(.text._ZN5boost9iostreams6detail22lzma_decompressor_implISaIcEEC2Ev[_ZN5boost9iostreams6detail22lzma_decompressor_implISaIcEEC5Ev]+0x24): undefined reference to `boost::iostreams::detail::lzma_base::lzma_base()'
(etc)

I now wonder whether the shipped boost library was built without lzma support (but then why is there an lzma include file?). More generally, I wonder whether (and how) I can check the build options that were used for the boost library that was shipped.

I understand I can built my boost library from scratch, but would only do this if I really need to.

Update: My code is more complex, but below is a minimum example essentially taken from here that demonstrates the problem:

This works:

#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <fstream>
#include <iostream>

namespace io = boost::iostreams;

void foo(std::string input_file_path, std::string output_file_path) {
    namespace io = boost::iostreams;

    std::ifstream file(input_file_path, std::ios::binary);
    std::ofstream out(output_file_path, std::ios::binary);

    boost::iostreams::filtering_istreambuf in;
    in.push(io::bzip2_decompressor());
    in.push(file);

    io::copy(in, out);
}

int main() {
    foo("test.cpp.bz2", "output.txt");
}

This does not compile (with g++ test.cpp -lboost_iostreams):

#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/lzma.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <fstream>
#include <iostream>

namespace io = boost::iostreams;

void foo(std::string input_file_path, std::string output_file_path) {
    namespace io = boost::iostreams;

    std::ifstream file(input_file_path, std::ios::binary);
    std::ofstream out(output_file_path, std::ios::binary);

    boost::iostreams::filtering_istreambuf in;
    in.push(io::lzma_decompressor());
    in.push(file);

    io::copy(in, out);
}

int main() {
    foo("test.cpp.lzma", "output.txt");
}
user52366
  • 1,035
  • 1
  • 10
  • 21
  • First please try to create a [mcve] of your code to show us. Then please tell us how you attempt to build the code, what flags and (more importantly) what libraries you provide when linking. – Some programmer dude Oct 29 '19 at 11:35
  • Ok, I have added an example for bzip2 (that works) and lzma (that does not compile). – user52366 Oct 29 '19 at 12:20
  • Ok, I have now built the boost library from source (1.71) and everything works. The question remains why the include file is provided if the code is not in the library, and how I can check the build options for pre-installed libraries. – user52366 Oct 29 '19 at 12:35

0 Answers0