2010-08-14 131 views
7

问候,如何为使用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”。

回答

4

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

-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环境变量太多。

+1

谢谢。正如你所建议的那样,链接器只需要“-pg”选项。 SCons将此变量视为“LINKFLAGS”。 – kobrien 2010-08-14 18:31:17