GCC 编译选项语法

发布于 2024-12-16 20:25:53 字数 1066 浏览 5 评论 0原文

我正在尝试 gprof 我的程序。我想要逐行分析。 但是,我似乎无法正确理解语法。我使用的是“make”而不是“gcc”,所以请只提供适合 make 的建议。如果您能给我完整的“make”语法,我将非常感激。 基于该网站: http://sourceware.org/binutils/docs/gprof/Output-Options.html [^] http://sourceware.org/binutils/docs/gprof/Line_002dby_002dline.html [^] 这是我输入的内容:

make USE_LOCAL_HEADERS=0 LDFLAGS='-L.' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -l -g'

输出是:

/usr/bin/ld: cannot find -l-g
collect2: ld returned 1 exit status
make[2]: *** [build/release-linux-ppc64/ioquake3.ppc64] Error 1
make[2]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make[1]: *** [targets] Error 2
make[1]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make: *** [release] Error 2

我需要选项“-l”、“-g”和“-pg”。

I am trying to gprof my program. I want a line-by-line profiling.
However, I can't seem to get the syntax right. I am using "make" and not "gcc" so please help only with suggestions that fit make. I wouldbe very grateful if you can give me the full "make" syntax.
Based on this website:
http://sourceware.org/binutils/docs/gprof/Output-Options.html[^]
http://sourceware.org/binutils/docs/gprof/Line_002dby_002dline.html[^]
Here is what I am inputting:

make USE_LOCAL_HEADERS=0 LDFLAGS='-L.' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -l -g'

The output is:

/usr/bin/ld: cannot find -l-g
collect2: ld returned 1 exit status
make[2]: *** [build/release-linux-ppc64/ioquake3.ppc64] Error 1
make[2]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make[1]: *** [targets] Error 2
make[1]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make: *** [release] Error 2

I need option "-l", "-g" and "-pg".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

天生の放荡 2024-12-23 20:25:53

-pg 启用分析,-g 包含有助于解释生成的配置文件的符号名称。

-pg 选项需要传递给编译器链接器。

-l 命令在您使用它的方式中没有意义,因为它需要一个库名称作为参数,因此只要您不提供库名称,就保留 -l< /code> 离开。

另外,在开发过程中,我建议使用 -Wall 选项来启用编译期间的所有警告。

所以你可以尝试这个 make 命令:

make USE_LOCAL_HEADERS=0 LDFLAGS='-L. -pg' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -g -Wall'

-pg enables profiling, -g includes symbol names which help interpreting the profile generated.

The -pg option needs to be passed to compiler and linker.

The -l command does not make sense in the way you are using it, as it needs a library name as parameter, so as long as you do not provide one, leave the -l away.

Also during development I'd recommend the -Wall option to enable all warnings during compilation.

So you might try this make command:

make USE_LOCAL_HEADERS=0 LDFLAGS='-L. -pg' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -g -Wall'
嗼ふ静 2024-12-23 20:25:53

您可以将其中大部分作为环境变量传递,让“应该”做正确的事情并将它们用于编译器:

$ USE_LOCAL_HEADERS=0 \
LDFLAGS='-L.' \
BASE_CFLAGS=-m32 \
CFLAGS='-fopenmp -pg -g' \
make

这将 USE_LOCAL_HEADERS、LDFLAGS、BASE_CFLAGS 和 CFLAGS 作为 make 和 gcc 可以看到的环境变量。您可能需要编辑 Makefile 以按照您想要的正确方式组合它们。

You can pass most of those as environment variables, make "should" do the right thing and use them for the compiler:

$ USE_LOCAL_HEADERS=0 \
LDFLAGS='-L.' \
BASE_CFLAGS=-m32 \
CFLAGS='-fopenmp -pg -g' \
make

That will USE_LOCAL_HEADERS, LDFLAGS, BASE_CFLAGS and CFLAGS as environment variables which make and gcc can see. You may have to edit your Makefile to combine them in the correct ways for what you want.

蓬勃野心 2024-12-23 20:25:53

make 只是“自动确定大型程序的哪些部分需要重新编译,并发出重新编译它们的命令”(man make)。看起来 make 无法理解你的论点;在遇到错误之前它实际上不会运行任何命令。

很抱歉,我无法进一步帮助您,但您的问题出在您的 make 文件或类似文件中。您应该阅读什么是 make 文件,以及如何 gprof 您的程序并了解 make 和 gcc 之间的区别,并重新评估您正在尝试执行的操作。 make 可能对你没用。

make is simply a "to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them" (man make). It looks like make cannot make sense of your arguments; it doesn't actually get to run any commands before it encounters an error.

I'm sorry I can't help you any further, but your problem is within your make file or similar. You should read up on what a make file is, and how to gprof your program and understand the difference between make and gcc, and reevaluate what you are trying to do. Make may not be useuful to you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文