C++无法链接 Boost 库

发布于 2024-11-06 00:30:54 字数 1211 浏览 0 评论 0原文

我正在尝试从 boost 文档编译这一小段代码: (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 to out using std::ostream interface
}

但它拒绝编译,我收到以下错误:

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:在函数“int main()”中:

../teste/main.cpp:9:25:错误:“压缩机”是未在此范围内声明

../teste/main.cpp:10:29:错误:未在此范围内声明“base64_encoder”

../teste/main.cpp:11:37:错误:未声明“file_sink”在这个范围内,

我知道我可能做了一些愚蠢的事情,但我只是看不到什么......

编辑:

顺便说一句,我已经正确安装了所有boost库和-dev文件。我正在使用 QT-Creator,所以我的 .pro 文件如下所示:

SOURCES += \
    main.cpp

LIBS += \
    -lboost_filesystem \
    -lboost_iostreams 

I'm trying to compile this little piece of code from the 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 to out using std::ostream interface
}

But it refuses to compile, I get the 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’ was not declared in this scope

../teste/main.cpp:10:29: error: ‘base64_encoder’ was not declared in this scope

../teste/main.cpp:11:37: error: ‘file_sink’ was not declared in this scope

I know I'm probably doing something stupid but I just can't see what...

edit:

BTW, I have all boost libraries and -dev files installed properly. and I'm using QT-Creator, so my .pro file looks like so:

SOURCES += \
    main.cpp

LIBS += \
    -lboost_filesystem \
    -lboost_iostreams 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

强辩 2024-11-13 00:30:54

我假设您指的是

http: //www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/tutorial/filter_usage.html

如果您仔细阅读,您会注意到教程页面指出

如果你有合适的输出过滤器
压缩器和base64_encoder,你可以
按如下方式执行此操作

此示例页面上的代码并不意味着可编译。请尝试以下示例:

http:// www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/classes/zlib.html#examples

...但请务必添加另一个using namespace boost::iostreams 能够编译它,即:

#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);
}

I assume you are refering to the example at

http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/tutorial/filter_usage.html

If you read carefully, you will notice that the tutorial page states that

If you have appropriate OutputFilters
compressor and base64_encoder, you can
do this as follows

The code on this example page is not meant to be compilable. Try this example instead:

http://www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/classes/zlib.html#examples

...but be sure to add another using namespace boost::iostreams to be able to 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);
}
他不在意 2024-11-13 00:30:54

该示例并不完整,它仅显示了 io::filtering_ostream out 的用法;但它无效,因为它没有声明或包含compressor()的必要代码; base64_encoder 和 file_sink 函数。

The example is not complete it just shows the usage of io::filtering_ostream out; but its not valid since its not declaring or including the necessary code for the compressor(); base64_encoder and file_sink functions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文