0

私はそのような単純なコードをコンパイルしたい:

#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"andに静的にコンパイルしました"C:\Program Files\bzip2" (tham のlibandincludeフォルダーを使用)。

シンプルな VS2010 プロジェクトを作成し、静的にリンクされたブースト、リンクされた 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

したがって、すべてのブーストがコンパイルされた後、または再構築する必要がある場合、zlib をブースト Iostream に接続できるのでしょうか]、そうであれば、100% 静的にリンクされた通常の Boost + Boost.Iostreams (zlib サポート付き) を取得するには、どの引数を追加すればよいでしょうか?

4

1 に答える 1

3

まず第一に、コードは適切に構成されたシステムでもコンパイルされません: ソースとして (ストリームではなく) 文字列を使用しようとgzip_decompressorし、プレーンな ASCII 文字列に適用しようとします。

次のコードは、Visual Studio 2010 SP1 でコンパイルおよび実行されます。BoostProインストーラーによってすべてのデフォルト オプションがインストールされ、他のライブラリはインストールされていません。

#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);
}
于 2011-11-18T22:43:29.467 に答える