0

I'm trying to write a function that compresses a data buffer and writes it to a file, but I'm having trouble getting it to build properly. The code itself is pretty straightforward:

void writeToFile(std::string fileName, const char* buf, size_t bufSize) {
    boost::filesystem::ofstream outFile(fileName, std::ios::out | std::ios::binary | std::ios::trunc);

    boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
    out.push(boost::iostreams::lzma_compressor());
    out.push(outFile);

    boost::iostreams::copy(boost::iostreams::basic_array_source<char>(buf, bufSize), out);
}

However, when I try to build it, I get a bunch of linking errors:

  • Undefined symbol: boost::iostreams::lzma_error::check(int)
  • Undefined symbol: boost::iostreams::lzma::stream_end
  • Undefined symbol: boost::iostreams::lzma::default_compression
  • etc.

I'm already linking to both libboost_iostreams-mt and libboost_system-mt, since if I use bzip2 or zlib equivalents, everything builds just fine.

I currently get boost through MacPorts, and I have version 1.71. (I updated my ports and ran sudo port install boost a few hours ago.) Running nm on my copy of libboost_iostreams-mt.dylib shows symbols related to many other compression algorithms that Boost.Iostreams offers, but the LZMA-related symbols are nowhere to be found. What can I do to get a library with the proper symbols I need?

(Technically, I don't NEED to use LZMA for my purposes here, and I could probably also work around this by grabbing lzma.cpp from here and compiling it in with everything else, but I'm still curious as to what a general fix would be.)

Edit 1:

In response to n.m.'s comment, I'm building this as a command line tool through Xcode against the .xcconfig file below, so my exact build command is whatever Xcode spits out.

HEADER_SEARCH_PATHS = $(inherited) /opt/local/include/
LIBRARY_SEARCH_PATHS = $(inherited) /opt/local/lib/

OTHER_LDFLAGS = $(inherited) -lboost_iostreams-mt -lboost_system-mt
Adam
  • 53
  • 4

0 Answers0