You are not logged in.

#1 2012-05-18 12:20:15

linux-ka
Member
From: ADL
Registered: 2010-05-07
Posts: 232

Failing to use gzstream

Hi,

I try using gzstream. My very first code is just to see how it works.

#include <iostream>
#include <fstream>
#include <gzstream.h>
#include <string>

int main(int argc, char **argv)
{

std::string file,file2 ;

file = "test" ;
file2 = "test.zip" ;

std::ofstream out(file.c_str(),std::ofstream::binary) ;

out << argv[1] ;

out.close() ;

ogzstream out_zip ;

out_zip.open(file2.c_str()); //,ogzstream::binary) ;

out_zip << argv[1] ;

out_zip.close() ;

return 0 ;
}

But when compiling

g++ -l gzstream myzip.cpp -Wall

I get the following error message:

/tmp/ccnWQAid.o: In function `main':
myzip.cpp:(.text+0x108): undefined reference to `gzstreambase::close()'
/tmp/ccnWQAid.o: In function `gzstreambuf::gzstreambuf()':
myzip.cpp:(.text._ZN11gzstreambufC2Ev[_ZN11gzstreambufC5Ev]+0x17): undefined reference to `vtable for gzstreambuf'
/tmp/ccnWQAid.o: In function `gzstreambuf::~gzstreambuf()':
myzip.cpp:(.text._ZN11gzstreambufD2Ev[_ZN11gzstreambufD5Ev]+0xc): undefined reference to `vtable for gzstreambuf'
myzip.cpp:(.text._ZN11gzstreambufD2Ev[_ZN11gzstreambufD5Ev]+0x17): undefined reference to `gzstreambuf::close()'
/tmp/ccnWQAid.o: In function `ogzstream::ogzstream()':
myzip.cpp:(.text._ZN9ogzstreamC1Ev[_ZN9ogzstreamC1Ev]+0x8c): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/ccnWQAid.o: In function `ogzstream::open(char const*, int)':
myzip.cpp:(.text._ZN9ogzstream4openEPKci[_ZN9ogzstream4openEPKci]+0x1b): undefined reference to `gzstreambase::open(char const*, int)'
/tmp/ccnWQAid.o: In function `ogzstream::~ogzstream()':
myzip.cpp:(.text._ZN9ogzstreamD1Ev[_ZN9ogzstreamD1Ev]+0x5a): undefined reference to `gzstreambase::~gzstreambase()'
myzip.cpp:(.text._ZN9ogzstreamD1Ev[_ZN9ogzstreamD1Ev]+0xa5): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/ccnWQAid.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x8): undefined reference to `typeinfo for gzstreambase'
/tmp/ccnWQAid.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0xc): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/ccnWQAid.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x10): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/ccnWQAid.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x1c): undefined reference to `typeinfo for gzstreambase'
/tmp/ccnWQAid.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x20): undefined reference to `virtual thunk to gzstreambase::~gzstreambase()'
/tmp/ccnWQAid.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x24): undefined reference to `virtual thunk to gzstreambase::~gzstreambase()'
/tmp/ccnWQAid.o:(.rodata._ZTI9ogzstream[_ZTI9ogzstream]+0x10): undefined reference to `typeinfo for gzstreambase'
collect2: Fehler: ld gab 1 als Ende-Status zurück

So, removing the out_zip.close() line I receive the following error:

/tmp/cc5AZiFe.o: In function `gzstreambuf::gzstreambuf()':
myzip.cpp:(.text._ZN11gzstreambufC2Ev[_ZN11gzstreambufC5Ev]+0x17): undefined reference to `vtable for gzstreambuf'
/tmp/cc5AZiFe.o: In function `gzstreambuf::~gzstreambuf()':
myzip.cpp:(.text._ZN11gzstreambufD2Ev[_ZN11gzstreambufD5Ev]+0xc): undefined reference to `vtable for gzstreambuf'
myzip.cpp:(.text._ZN11gzstreambufD2Ev[_ZN11gzstreambufD5Ev]+0x17): undefined reference to `gzstreambuf::close()'
/tmp/cc5AZiFe.o: In function `ogzstream::ogzstream()':
myzip.cpp:(.text._ZN9ogzstreamC1Ev[_ZN9ogzstreamC1Ev]+0x8c): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/cc5AZiFe.o: In function `ogzstream::open(char const*, int)':
myzip.cpp:(.text._ZN9ogzstream4openEPKci[_ZN9ogzstream4openEPKci]+0x1b): undefined reference to `gzstreambase::open(char const*, int)'
/tmp/cc5AZiFe.o: In function `ogzstream::~ogzstream()':
myzip.cpp:(.text._ZN9ogzstreamD1Ev[_ZN9ogzstreamD1Ev]+0x5a): undefined reference to `gzstreambase::~gzstreambase()'
myzip.cpp:(.text._ZN9ogzstreamD1Ev[_ZN9ogzstreamD1Ev]+0xa5): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/cc5AZiFe.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x8): undefined reference to `typeinfo for gzstreambase'
/tmp/cc5AZiFe.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0xc): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/cc5AZiFe.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x10): undefined reference to `gzstreambase::~gzstreambase()'
/tmp/cc5AZiFe.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x1c): undefined reference to `typeinfo for gzstreambase'
/tmp/cc5AZiFe.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x20): undefined reference to `virtual thunk to gzstreambase::~gzstreambase()'
/tmp/cc5AZiFe.o:(.rodata._ZTC9ogzstream0_12gzstreambase[_ZTV9ogzstream]+0x24): undefined reference to `virtual thunk to gzstreambase::~gzstreambase()'
/tmp/cc5AZiFe.o:(.rodata._ZTI9ogzstream[_ZTI9ogzstream]+0x10): undefined reference to `typeinfo for gzstreambase'
collect2: Fehler: ld gab 1 als Ende-Status zurück

So what wrong with it? I installed it from AUR. I also installed from source by downloading from their webpage, but it doesn't work. Strangely, the make test of the source tarball works fine.

I don't see how to tinker this issue....I hope you can help me finding the problem.

Thanks,

L-K

Offline

#2 2012-05-18 13:15:49

linux-ka
Member
From: ADL
Registered: 2010-05-07
Posts: 232

Re: Failing to use gzstream

Well,

I changed the order of g++ flags

g++ myzip.cpp -lgzstream -lz -Wall

and finally it works....hell, I don't understand this...so there is any defined order of how to put g++ parameters? That never occured to me.

L-K

Offline

Board footer

Powered by FluxBB