如何为使用SCons构建的程序构建gprof支持?

问候,

这是我的SConstruct文件

env = Environment()
env.Append(CCFLAGS=['-g','-pg'])
env.Program(target='program1',source= ['program1.c'])

这里还有编译的输出

scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
gcc -o program1.o -c -g -pg program1.c
gcc -o program1 program1.o
scons: done building targets.

如您所见,我将“-pg”选项传递给构建环境.在我构建之后,我运行程序来生成“gmon.out”但它没有生成.

谁能证实这个问题?还是有解决方案?

谢谢.

更新:

感谢此处给出的建议,更新的工作SConstruct文件如下所示.链接器需要标志,因此要通过scons传递它,必须使用“LINKFLAGS”选项.

env = Environment()
env.Append(CCFLAGS=['-g','-pg'],LINKFLAGS=['-pg'])
env.Program(target='program1',source= ['program1.c'])

编译输出

scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
gcc -o program1.o -c -g -pg program1.c
gcc -o program1 -pg program1.o
scons: done building targets.

请注意链接阶段中的附加“-pg”.

解决方法

在这种情况下,链接器还需要-pg选项.来自GCC man mage:

-pg Generate extra code to write profile information suitable for the analysis program gprof. You must use this option when compiling the source files you want data about,and you must also use it when linking.

尝试将选项添加到LDFLAGS环境变量中.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...