我有一个 C++ 软件,它在 boost::iostreams::filtering_istreambuf 上使用 bzip2 解压缩器。这很好用。
我现在尝试将其更改为也支持 lzma 解压缩。相应的包含文件似乎在我的 ubuntu 18.04 安装中:
$ 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)
但是,代码没有链接,我收到如下错误消息:
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)
我现在想知道发布的 boost 库是否是在没有 lzma 支持的情况下构建的(但是为什么会有 lzma 包含文件?)。更一般地说,我想知道是否(以及如何)检查用于已发布的 boost 库的构建选项。
我知道我可以从头开始构建我的 boost 库,但只有在我真的需要时才会这样做。
更新:我的代码更复杂,但下面是一个基本上取自这里的最小示例,它演示了这个问题:
这有效:
#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");
}
这不会编译(使用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");
}