Link to home
Start Free TrialLog in
Avatar of thready
thready

asked on

using zlib with boost - can't compile

Hi Experts,

I'm trying to set up streams with boost, writing to a compressed stream - I'm 99.9% sure I've done everything exactly as stated in the installation notes found on http://boost.org/libs/iostreams/doc/index.html?path=7.  From the small code fragment below, I get the following compiler errors:
error C2065: 'zlib_compressor' : undeclared identifier
error C2065: 'base64_encoder' : undeclared identifier
error C2065: 'file_sink' : undeclared identifier

I have included the following at the top of my file:


io::filtering_ostream out;
    out.push(zlib_compressor());
    out.push(base64_encoder());
    out.push(file_sink(strFilename));
 
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include "..\inc\zlib.h"
#include "..\inc\zconf.h"
 
I have added the zlib.cpp to my Visual C++ 6.0 project.
I have added the preprocessor definition BOOST_IOSTREAMS_NO_LIB to my project.
I am linking to ..\lib\zlib.dll  (but I guess this is not important yet)...
 
Any ideas at all would be extremely appreciated!
 
Many thanks,
Mike

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Soory, I for got - add theabove line after your #include directives.
Sorry, according to http://www.boost.org/libs/iostreams/doc/classes/zlib.html , the following should work:
#include <fstream>
#include <iostream>
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
 
int main() 
{
    using namespace std;
 
    ifstream file("hello.z", ios_base::in | ios_base::binary);
    filtering_streambuf<input> in;
    in.push(zlib_decompressor());
    in.push(file);
    boost::iostreams::copy(in, cout);
}

Open in new window

Avatar of thready
thready

ASKER

Hi jkr,

I tried it - extra compile error:
error C2871: 'zlib' : does not exist or is not a namespace

Any idea what I could have forgot?

The important includes are as follows at the top of my file:
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include "..\inc\zlib.h"
#include "..\inc\zconf.h"
 
namespace io = boost::iostreams;
using namespace zlib;

Open in new window

Avatar of thready

ASKER

No luck with the other one either - not that the link you provided shows that there is extra stuff required because compressors require 3rd party software to be "linked" to....

http://www.boost.org/libs/iostreams/doc/classes/zlib.html  (at the end of this page)
Ooops, might be

using namespace boost::iostreams::zlib;
Avatar of thready

ASKER

>> using namespace boost::iostreams::zlib;

nope - still undefined for zlib_compressor..

I've been at this for 7 hours....  I'm new to namespaces and pulling my hair out slowly....  :-)
Avatar of thready

ASKER

The solution was really to prepend boost::iostreams:: to my compressor (or just io:: since it was defined as boost::iostreams)  FEWF - Thanks for pointing me in the right direction!
Hm, I have been lloking around for a while and cannot find anything obvious. But, there *is* one thing: The class is declared as

template<typename Alloc = std::allocator<char> >
struct basic_zlib_compressor {
    typedef char                    char_type;
    typedef implementation-defined  category;

    basic_zlib_compressor( const zlib_params& = zlib::default_compression,
                           std::streamsize buffer_size = default value );

    // DualUseFilter members.
};

typedef basic_zlib_compressor<> zlib_compressor;

Now, you are using Visual C++ 6.0, which is infamous for the trouble it causes with template specializations. Can you give that a try with a more recent version (VS 2008 is available from http://msdn.microsoft.com/vstudio/express/ for free, VS 2005 from http://www.microsoft.com/downloads/details.aspx?FamilyID=7b0b0339-613a-46e6-ab4d-080d4d4a8c4e&DisplayLang=en)
Avatar of thready

ASKER

No wonder I've been having so much trouble.  Time to upgrade huh!?  I will when I get the chance.  Right now I'm worried that I won't even be able to build my project correcly in VS 2005... Is this something I shouldn't be worried about?
From my experience, you might have some trouble, depending on what is in your project, but nothing that is not feasible. Mostly complains about 'deprecated' functions, which can be turned off by macros. But, it is definitely worth the switch.
Avatar of thready

ASKER

Any really quick 'off hand' examples?  I'm probably gonna go out and buy VS 2008 tomorrow.....
Hey, try the express version for free before you buy. Nothing against the latter, but already having ported the code you need gives you a lot more security to do that.
Avatar of thready

ASKER

Hi jkr,
I downloaded the express version but it doesn't look like there is support for MFC - is this correct?

Mike
Yes, there's no MFC support in there.