【问题标题】:How to get around building Boost.Iostreams separatly with zip (gz) support on Windows?如何绕过在 Windows 上使用 zip (gz) 支持单独构建 Boost.Iostreams?
【发布时间】:2011-11-18 11:51:10
【问题描述】:

我想编译这样的simple code:

#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 Files\Boost" --without-mpi --without-python link=static runtime-link=static install

到那时,我的系统中还没有安装 zlibbzip2。现在我将zlib和bzib2静态编译成"C:\Program Files\zlib""C:\Program Files\bzip2"(在tham中有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.0\include\boost\iostreams\traits.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.0\include\boost\iostreams\traits.hpp  
Error   2   error C2146: syntax error : missing ';' before identifier 'type'    c:\program files (x86)\boost-1.47.0\include\boost\iostreams\traits.hpp  242
Error   4   error C2208: 'boost::type' : no members defined using this type c:\program files (x86)\boost-1.47.0\include\boost\iostreams\traits.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.0\include\boost\iostreams\traits.hpp  242

所以我想知道在编译完所有 boost 之后 zlib 是否可以连接到 boost Iostreams 或者我必须重建它],如果是的话,我应该添加什么参数来获得 100% 静态链接的普通 Boost + Boost.Iostreams(使用 zlib支持)?

【问题讨论】:

    标签: c++ visual-studio-2010 boost zlib boost-iostreams


    【解决方案1】:

    首先,即使在正确配置的系统上,代码也无法编译:它尝试使用字符串(不是流)作为源,并尝试将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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      • 2016-02-17
      • 2010-09-16
      • 1970-01-01
      • 2014-09-28
      • 2020-09-19
      相关资源
      最近更新 更多