如何绕过构建Boost.在Windows上单独使用zip (gz)支持io流



我想编译这样简单的代码:

#include <iostream>
#include <fstream>
#include <string>
#include <zlib.h>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
    std::string hello =  "Hello world";
    std::ofstream zip_png_file( "hello.gz",  std::ofstream::binary);
    boost::iostreams::filtering_streambuf< boost::iostreams::input> in;
    in.push( boost::iostreams::gzip_decompressor());
    in.push(hello);
    boost::iostreams::copy(in, zip_png_file);
    std::cin.get();
    return 0;
}

我用:

编译Boost
-j4 --prefix="C:Program FilesBoost" --without-mpi --without-python link=static runtime-link=static install
那时我的系统中还没有安装zlibbzip2。现在我将zlib和bzib2静态编译为"C:Program Fileszlib""C:Program Filesbzip2"(其中包含libinclude文件夹)

我创建了简单的VS2010项目和静态链接boost,链接zip添加了包含文件夹。但是没有编译,我得到了5个错误:

Error   5   error C1903: unable to recover from previous error(s); stopping compilation c:program files (x86)boost-1.47.0includeboostiostreamstraits.hpp  242
Error   1   error C2039: 'category' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' c:program files (x86)boost-1.47.0includeboostiostreamstraits.hpp  
Error   2   error C2146: syntax error : missing ';' before identifier 'type'    c:program files (x86)boost-1.47.0includeboostiostreamstraits.hpp  242
Error   4   error C2208: 'boost::type' : no members defined using this type c:program files (x86)boost-1.47.0includeboostiostreamstraits.hpp  242
Error   3   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:program files (x86)boost-1.47.0includeboostiostreamstraits.hpp  242

所以我想知道zlib可以连接到boost Iostreams后,所有boost编译或我必须重建它],如果是的话,我应该添加什么参数到我的得到100%静态链接正常boost + boost。Iostreams(支持zlib)?

首先,即使在正确配置的系统上,代码也无法编译:它试图使用字符串(而不是流)作为源,并试图将gzip_decompressor应用于普通ASCII字符串。

下面的代码编译并运行在Visual Studio 2010 SP1上,使用BoostPro安装程序安装的boost和所有默认选项,没有安装其他库。

#include <fstream>
#include <sstream>
#include <string>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/gzip.hpp>
int main()
{
    std::string hello = "Hello world";
    std::istringstream src(hello);
    boost::iostreams::filtering_streambuf< boost::iostreams::input> in;
    in.push(boost::iostreams::gzip_compressor());
    in.push(src);
    std::ofstream zip_png_file( "hello.gz",  std::ofstream::binary);
    boost::iostreams::copy(in, zip_png_file);
}

最新更新