C++无法链接 Boost 库
我正在尝试从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您指的是
http: //www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/tutorial/filter_usage.html
如果您仔细阅读,您会注意到教程页面指出
此示例页面上的代码并不意味着可编译。请尝试以下示例:
http:// www.boost.org/doc/libs/1_46_1/libs/iostreams/doc/classes/zlib.html#examples
...但请务必添加另一个
using namespace boost::iostreams
能够编译它,即: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
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.:该示例并不完整,它仅显示了 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.