DLDFLAGS 和 LDFLAGS 有什么区别

发布于 2024-12-27 19:36:41 字数 91 浏览 3 评论 0原文

一个简单的问题。我在示例 Makefile 中发现了“DLDFLAGS”和“LDFLAGS”。使用的编译器是gcc。看起来它们都用于链接器。我想知道它们之间有什么区别。

A quick question. I found both "DLDFLAGS" and "LDFLAGS" in a sample Makefile. The compiler used is gcc. It looks like they are both used for linkers. I'm wondering what's the difference between them.

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

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

发布评论

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

评论(2

-柠檬树下少年和吉他 2025-01-03 19:36:41

LDFLAGS 通常设置为包含传递给链接器的选项(因此可能包括所需的库)。与 CFLAGS 一起,它们通常被设置为开发人员环境变量的一部分,并且 make 会了解它们,因此会主动查看它们是否已设置并将它们传递给给编译器。

例如,如果我在环境中将 CFLAGS 设置为 -O2 -Wall,那么如果我在没有 Makefile 的情况下键入 make hello,make 将自动将编译器调用为 gcc -O2 -Wall hello.c -o hello.o。然后它将以类似的方式调用链接器,将 LDFLAGS 中的标志添加到命令行。

Makefile 可以显式覆盖 LDFLAGSCFLAGS

另一方面,DLDFLAGS 不是众所周知/定义的变量,因此它可能特定于特定的 Makefile。您必须阅读 Makefile 才能了解它是如何使用的。例如,如果设置了 LDFLAGS,它可能会定义要使用的链接器标志 - 请阅读 Makefile 以进行确定。

LDFLAGS is normally set to contain options that are passed through to the linker (so may include required libraries). Together with CFLAGS, these are often set as part of a developers environment variables and make will know about them so will actively look to see if they're set and pass them through to the compiler.

For example, if I set CFLAGS in my environment to -O2 -Wall, then if I type make hello with no Makefile, make will automatically invoke the compiler as gcc -O2 -Wall hello.c -o hello.o. Then it'll invoke the linker in a similar way, adding the flags in LDFLAGS to the command line.

Makefiles can explicitly override both LDFLAGS and CFLAGS.

DLDFLAGS on the other hand is not a well known/defined variable, so it's likely to be specific to that particular Makefile. You'd have to read the Makefile to find out how it's used. It may, for example, define linker flags to use if LDFLAGS is set - read the Makefile to find out for sure.

调妓 2025-01-03 19:36:41

DLDFLAGS 不只是一个定义名为“LDFLAGS”的宏的预编译器标志吗?

来自海湾合作委员会手册:

-D名称

将 name 预定义为宏,定义为 1

Isn't DLDFLAGS just a precompiler flag that defines macro named "LDFLAGS"?

From gcc manual:

-D name

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