linux - C++ Can't link Boost library -
i'm trying compile little piece of code boost documentation: (http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/tutorial/filter_usage.html)
#include <boost/iostreams/device/file_descriptor.hpp> #include <boost/iostreams/filtering_stream.hpp> namespace io = boost::iostreams; int main() { io::filtering_ostream out; out.push(compressor()); out.push(base64_encoder()); out.push(file_sink("my_file.txt")); // write out using std::ostream interface }
but refuses compile, following errors:
g++ -c -pipe -g -wall -w -d_reentrant -dqt_gui_lib -dqt_core_lib -dqt_shared -i/usr/share/qt4/mkspecs/linux-g++ -i../teste -i/usr/include/qt4/qtcore -i/usr/include/qt4/qtgui -i/usr/include/qt4 -i. -i../teste -i. -o main.o ../teste/main.cpp
../teste/main.cpp: in function ‘int main()’:
../teste/main.cpp:9:25: error: ‘compressor’ not declared in scope
../teste/main.cpp:10:29: error: ‘base64_encoder’ not declared in scope
../teste/main.cpp:11:37: error: ‘file_sink’ not declared in scope
i know i'm doing stupid can't see what...
edit:
btw, have boost libraries , -dev files installed properly. , i'm using qt-creator, .pro file looks so:
sources += \ main.cpp libs += \ -lboost_filesystem \ -lboost_iostreams
i assume refering example at
http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/tutorial/filter_usage.html
if read carefully, notice tutorial page states that
if have appropriate outputfilters compressor , base64_encoder, can follows
the code on example page not meant compilable. try example instead:
http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/classes/zlib.html#examples
...but sure add using namespace boost::iostreams
able compile it, i.e.:
#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; using namespace boost::iostreams; 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); }
Comments
Post a Comment