问题描述
我使用Boost :: iostreams同时写入我的控制台和一个文件。当我使用eclipse进行调试时(使用gdb当然),我收到一条警告,说RTTI符号找不到我从Boost :: iostreams使用的其中一个类。
以下是重现问题的最简单代码。
#ifndef BOOST_IO_STREAM_H_
#define BOOST_IO_STREAM_H_
#include< fstream>
#include< boost / iostreams / tee.hpp>
#include< boost / iostreams / stream.hpp>
使用boost :: iostreams :: tee_device;
使用boost :: iostreams :: stream;
typedef tee_device< std :: ostream,std :: ofstream> TeeDevice;
typedef stream< TeeDevice> TeeStream;
#endif / * BOOST_IO_STREAM_H_ * /
int
main()
{
/ *配置文件输出实验细节* /
std :: string self_filename =./experimentconfig.txt;
std :: ofstream fconfig(self_filename.c_str());
TeeDevice my_tee(std :: cout,fconfig);
TeeStream cool_cout(my_tee);
cool_cout<< 在实验运行期间输出到文件和控制台<<的std :: ENDL;
返回0;
}
当我跨越 TeeStream cool_cout(my_tee);
在调试过程中,我收到以下警告:
警告:RTTI符号未找到类' boost :: iostreams :: stream< boost :: iostreams :: tee_device< std :: ostream,std :: basic_ofstream< char,std :: char_traits< char> > >,std :: char_traits< char>,std :: allocator< char> >'
warning:为类'boost :: iostreams :: stream_buffer< boost :: iostreams :: tee_device< std :: ostream,std :: basic_ofstream< char,std :: char_traits< char>'找不到RTTI符号; > >,std :: char_traits< char>,std :: allocator< char> ;, boost :: iostreams :: output>'
遇到对象cool_cout时会重复警告。我该如何解决?当然,使用这些代码的程序工作,我没有问题。警告不应该被忽略,并且有关于必须获得的RTTI符号的知识。 (我不能用-f nortti编译,那么可执行文件会抱怨rtti应该启用iostreams)
关心的是编译器,这是实际创建程序的原因。最终用户不应该使用调试器,它不会影响你的二进制文件本身。虽然gdb有时会发现问题,但其中的许多警告是因为gdb消耗调试符号,并且消费者(gdb)具有错误和防卫。通常他们只是减少gdb的功能。
在这种情况下,调试器中可用的类更少。它使调试更加困难,但不会损害应用程序本身。
您有几个选择来处理这个错误。
- 忽略gdb中的警告并继续使用。
- 获取gdb的源代码并尝试找到问题并提交补丁。我确信它会受到欢迎。
- 使用不同的调试器。 (尽管我看到所有的替代品都是付费产品。) 改写程序以不使用任何模板。 gdb模板处理是存在大部分符号查找问题的地方。
I use Boost::iostreams to write simultaneously to my console and a file. When i use eclipse to debug(with gdb of course), i receive a warning which says RTTI symbol not found for one of the classes that i am using from Boost::iostreams.
Here is the minimal code to reproduce the problem.
#ifndef BOOST_IO_STREAM_H_
#define BOOST_IO_STREAM_H_
#include <fstream>
#include <boost/iostreams/tee.hpp>
#include <boost/iostreams/stream.hpp>
using boost::iostreams::tee_device;
using boost::iostreams::stream;
typedef tee_device<std::ostream, std::ofstream> TeeDevice;
typedef stream<TeeDevice> TeeStream;
#endif /* BOOST_IO_STREAM_H_ */
int
main()
{
/* A config file to output experiment details */
std::string self_filename = "./experimentconfig.txt";
std::ofstream fconfig(self_filename.c_str());
TeeDevice my_tee(std::cout, fconfig);
TeeStream cool_cout(my_tee);
cool_cout << "Output to file and console during experiment run" << std::endl;
return 0;
}
When i cross the TeeStream cool_cout(my_tee);
line during debugging, i receive the below warnings:
warning: RTTI symbol not found for class 'boost::iostreams::stream<boost::iostreams::tee_device<std::ostream, std::basic_ofstream<char, std::char_traits<char> > >, std::char_traits<char>, std::allocator<char> >'
warning: RTTI symbol not found for class 'boost::iostreams::stream_buffer<boost::iostreams::tee_device<std::ostream, std::basic_ofstream<char, std::char_traits<char> > >, std::char_traits<char>, std::allocator<char>, boost::iostreams::output>'
The warnings are repeated whenever the object cool_cout is encountered. How do i fix this? Of course, the programs which use this code works and i have no issues with that. Warnings are not supposed to be ignored and there is some knowledge out there about RTTI symbols which has to be gained. (I cannot compile with -f nortti then the executable complains that rtti should definitely be enabled to use iostreams)
Warnings you should be concerned about are from the compiler, which is what actually creates your program. End users should not be using a debugger, and it has no impact on your binary itself.
While gdb sometimes finds issues, many of the warnings in it are because gdb consumes debug symbols, and the consumer (gdb) has bugs and defencencies . Often they just reduce the functionality of gdb.In this case there is less information about that class available inside the debugger. It makes debugging more difficult, but doesn't hurt the application itself.
You have several choices for what to do about this error.
- Ignore the warning in gdb and go on with life.
- Get the sources for gdb and try to find the problem and submit a patch. I am sure it would be welcomed.
- Use a different debugger. (All alternates I have seen are paid products though.)
- Rewrite the program to not use any templates. gdb template handling is where the majority of symbol lookup issues exist.
这篇关于使用boost :: iostreams时未找到警告消息RTTI符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!