gpt4 book ai didi

c - GCC 的 "-Wl,option"和 "-Xlinker option"语法有区别吗?

转载 作者:太空狗 更新时间:2023-10-29 16:23:06 26 4
gpt4 key购买 nike

我一直在查看一些配置文件,并且看到它们都在使用(尽管在不同的体系结构上)。如果您在 Linux 机器上使用 GCC,那么将选项传递给链接器的两种语法之间是否存在差异?

阅读 GCC 手册,据我所知,它们的解释几乎相同。

最佳答案

来自 man gcc:

-Xlinker option

Pass option as an option to the linker. You can use this to supply system-specific linker options which GCC does not know how to recognize.

If you want to pass an option that takes a separate argument, you must use -Xlinker twice, once for the option and once for the argument. For example, to pass -assert definitions, you must write -Xlinker -assert -Xlinker definitions. It does not work to write -Xlinker "-assert definitions", because this passes the entire string as a single argument, which is not what the linker expects.

When using the GNU linker, it is usually more convenient to pass arguments to linker options using the option=value syntax than as separate arguments. For example, you can specify -Xlinker -Map=output.map rather than -Xlinker -Map -Xlinker output.map. Other linkers may not support this syntax for command-line options.

-Wl,option

Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas. You can use this syntax to pass an argument to the option.

For example, -Wl,-Map,output.map passes -Map output.map to the linker. When using the GNU linker, you can also get the same effect with -Wl,-Map=output.map.

如您所见,唯一的区别是 -Wl 允许您通过逗号指定多个参数,例如 -Wl,-rpath,/my/libs,这是你不能用 -Xlinker 做的;另一方面,-Xlinker 可能更具 self 描述性。拿你的选择。还要检查其他编译器(nvccclang)以查看它们是否同意语法,如果这对您很重要,则将其用于可移植性。

关于c - GCC 的 "-Wl,option"和 "-Xlinker option"语法有区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7221141/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com