Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6080636
  • 博文数量: 2759
  • 博客积分: 1021
  • 博客等级: 中士
  • 技术积分: 4091
  • 用 户 组: 普通用户
  • 注册时间: 2012-03-11 14:14
文章分类

全部博文(2759)

文章存档

2019年(1)

2017年(84)

2016年(196)

2015年(204)

2014年(636)

2013年(1176)

2012年(463)

分类: C/C++

2013-09-29 13:25:01

原文地址:记几个编译相关的问题 作者:zyd_cu

使用错误的头文件

某程序A使用了其它目录的某个头文件some_class.h中的类SomeClass,在SomeClass里增加了几个成员函数,在程序A中调用SomeClass调用新增加的成员函数,编译器一直提示“SomeClass没有这个成员函数”。对A进行预处理(gcc -E),从预处理结果发现,A使用了当前目录下的some_class.h的副本(NND,怎么来的?);本地删除掉some_class.h,问题解决。

头文件内容重复

上面那个问题,定位比较容易,接下来遇到的这个问题,最终定位到问题后撞墙的心都有了。vim操作时,将头文件的内容复制了一份,最终代码类似:

#ifndef SOME_CLASS_H_
#define SOME_CLASS_H_
class SomeClass
{
   // some member functions
   // many other lines
   public:
     int a;
     int b;
};
#endif

#ifndef SOME_CLASS_H_
#define SOME_CLASS_H_
class SomeClass
{
   // some member functions
   // many other lines
   public:
     int a;
     int b;
};
#endif 

上面的代码,由于宏保护的影响,最终代码只会被include一份,编译时不会报错。在SomeClass里增加一个新的成员变量c,由于vim的操作习惯,首先G移到文件末尾,然后添加成员变量c,编译时提示SomeClass不存在成员变量c,预编译后发现引用的头文件路径也是正确的。当局者迷,旁观者清,最后在同事的帮助下轻松的发现了这个问题。

backtrace没有行号信息

某程序调用库A时,程序coredump,gdb调试时,backtrace只能打印出一个函数调用链,没有调用时函数的参数值以及具体行号等,而且因为调用链并不完整,使得根本定位不到coredump的原因;编写另一个程序,调用库B,库A和库B构建时使用的编译链接参数完全相同(-g 加其它的选项),在程序里模拟coredump,backtrace能得到详细的调用堆栈信息;最后通过将A库的编译参数从-g改为-g3,问题解决。但从gcc的man手册里看到,-g3只是在宏扩展的调试有帮助;为什么A在使用-g时,堆栈信息不全,仍不得知,求达人解惑。

Request debugging information and also use level to specify how much information. The default level is 2.
Level 0 produces no debug information at all. Thus, -g0 negates -g.

Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug. This includes descriptions of functions and external variables, but no information about local variables and no line numbers.

Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.
阅读(751) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~