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

LVL 1
threadyAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
You'll need to add


using namespace zlib;

Open in new window

0
 
jkrCommented:
Soory, I for got - add theabove line after your #include directives.
0
 
jkrCommented:
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

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
threadyAuthor Commented:
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

0
 
threadyAuthor Commented:
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)
0
 
jkrCommented:
Ooops, might be

using namespace boost::iostreams::zlib;
0
 
threadyAuthor Commented:
>> 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....  :-)
0
 
threadyAuthor Commented:
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!
0
 
jkrCommented:
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)
0
 
threadyAuthor Commented:
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?
0
 
jkrCommented:
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.
0
 
threadyAuthor Commented:
Any really quick 'off hand' examples?  I'm probably gonna go out and buy VS 2008 tomorrow.....
0
 
jkrCommented:
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.
0
 
threadyAuthor Commented:
Hi jkr,
I downloaded the express version but it doesn't look like there is support for MFC - is this correct?

Mike
0
 
jkrCommented:
Yes, there's no MFC support in there.
0
All Courses

From novice to tech pro — start learning today.