6

我使用 Boost::iostreams 同时写入我的控制台和一个文件。当我使用 Eclipse 进行调试时(当然是使用 gdb),我收到一条警告,提示我在 Boost::iostreams 中使用的某个类中找不到 RTTI 符号。

这是重现问题的最少代码。

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

当我在调试期间越TeeStream cool_cout(my_tee);线时,我收到以下警告:

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>'

只要遇到对象cool_cout,就会重复警告。我该如何解决?当然,使用此代码的程序可以工作,我对此没有任何问题。不应忽略警告,并且必须获得一些关于 RTTI 符号的知识。(我无法使用 -f nortti 编译,然后可执行文件抱怨说绝对应该启用 rtti 以使用 iostreams)

4

1 回答 1

5

您应该关注的警告来自编译器,这是实际创建程序的原因。最终用户不应该使用调试器,它对您的二进制文件本身没有影响。

虽然 gdb 有时会发现问题,但其中的许多警告是因为 gdb 使用调试符号,而使用者 (gdb) 有错误和防御。通常他们只是减少 gdb 的功能。在这种情况下,调试器中可用的有关该类的信息较少。它使调试更加困难,但不会损害应用程序本身。

对于如何处理此错误,您有多种选择。

  1. 忽略 gdb 中的警告并继续生活。
  2. 获取 gdb 的源代码并尝试找出问题并提交补丁。我相信它会受到欢迎。
  3. 使用不同的调试器。(不过,我见过的所有替代品都是付费产品。)
  4. 重写程序以不使用任何模板。gdb 模板处理是大多数符号查找问题存在的地方。
于 2012-10-20T18:23:09.213 回答