代码之家  ›  专栏  ›  技术社区  ›  kobrien

如何为使用scons构建的程序内置gprof支持?

  •  7
  • kobrien  · 技术社区  · 14 年前

    问候语,

    这是我的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”,但它没有生成。

    有人能确认这个问题吗?或者有解决方案?

    谢谢。

    更新:

    根据这里给出的建议,更新的工作结构文件如下。链接器需要标志,因此要通过scon传递它,必须使用“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”。

    1 回复  |  直到 14 年前
        1
  •  4
  •   Nikolai Fetissov    14 年前

    链接器还需要 -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 环境变量也是。