如何建立,在gprof的支持与SCons的建造计划? [英] How to build-in gprof support to a program built with SCons?

查看:281
本文介绍了如何建立,在gprof的支持与SCons的建造计划?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,

下面是我的SConstruct文件:

  ENV =环境()
env.Append(CCFLAGS = [' - G',' - PG'])
env.Program(目标='程序1',源= ['program1.c'])

另外这里是编译器的输出:

  scons的:读SConscript文件...
scons的:读完SConscript文件。
scons的:建筑的目标...
GCC -o program1.o -c -g -pg program1.c
GCC -o程序1 program1.o
scons的:完成建设目标。

正如你可以看到我通过-pg选项编译环境。我建立之后,我运行程序来生成是gmon.out,但它不会产生。

任何人都可以证实这个问题?或者有一个解决方案?

感谢。

更新:

由于这里给出的建议,更新工作SConstruct文件如下。连接体需要的标志,因此,通过scons的通过它,必须使用LINKFLAGS选项。

  ENV =环境()
env.Append(CCFLAGS = [' - G',' - PG'],LINKFLAGS = [' - PG'])
env.Program(目标='程序1',源= ['program1.c'])

汇编输出:

  scons的:读SConscript文件...
scons的:读完SConscript文件。
scons的:建筑的目标...
GCC -o program1.o -c -g -pg program1.c
GCC -o程序1 -pg program1.o
scons的:完成建设目标。

请注意在链接阶段额外的-pg。


解决方案

链接器也需要在这种情况下, -pg 选项。从GCC人法师:

-pg 生成额外的code编写适合于分析程序gprof的概要文件信息。编译时需要有关数据源文件,和也必须使用它连接时,必须使用此选项。

尝试添加的选项 LDFLAGS 环境变量了。

Greetings,

Here is my SConstruct file:

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

Also here is the output of the compilation:

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.

As you can see I pass the "-pg" option to the build environment. After I build, I run the program to generate "gmon.out" but it isn't produced.

Can anyone confirm this problem? or have a solution?

Thanks.

Update:

Thanks to the advice given here, the updated working SConstruct file is as follows. The linker requires the flag, so to pass it through scons, the "LINKFLAGS" option must be used.

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

Output of compilation:

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.

Note the additional "-pg" in the linking phase.

解决方案

The linker also needs the -pg option in this case. From 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.

Try adding the option to LDFLAGS environment variable too.

这篇关于如何建立,在gprof的支持与SCons的建造计划?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆