"-Wl,option"和"-Wl,option"之间有区别吗?和"-Xlinker选项"GCC的语法? [英] Is there a difference between the "-Wl,option" and "-Xlinker option" syntax for GCC?

查看:75
本文介绍了"-Wl,option"和"-Wl,option"之间有区别吗?和"-Xlinker选项"GCC的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览一些配置文件,并且看到它们都被使用了(尽管在不同的体系结构上).如果您在Linux机器上使用GCC,则将选项传递到链接器的两种语法之间是否有区别?

I have been looking through some configuration files and I've seen both being used (albeit on different architectures). If you're using GCC on a Linux box, is there a difference between the two syntaxes for passing options to the linker?

在阅读GCC手册时,据我所知它们几乎完全相同.

Reading the GCC manual they are explained it almost identically as far as I could tell.

推荐答案

来自 man gcc :

-Xlinker选项

-Xlinker option

通过选项作为链接器的选项.您可以使用它来提供GCC不知道如何识别的系统特定的链接器选项.

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.

如果要传递带有单独参数的选项,则必须使用-Xlinker两次,一次用于该选项,一次用于该参数.例如,要传递-assert定义,必须编写-Xlinker -assert -Xlinker定义.编写-Xlinker"-assert definitions"是无效的,因为这会将整个字符串作为单个参数传递,这不是链接器所期望的.

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.

使用GNU链接器时,通常使用option = value语法将参数传递给链接器选项比将其作为单独的参数更方便.例如,您可以指定-Xlinker -Map = output.map而不是-Xlinker -Map -Xlinker output.map.其他链接器可能不支持命令行选项的这种语法.

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

-Wl,option

通过选项作为链接器的选项.如果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.

例如,-Wl,-Map,output.map将-Map output.map传递给链接器.使用GNU链接器时,还可以通过-Wl,-Map = output.map获得相同的效果.

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 可能更具描述性.随便你吧.还要检查其他编译器(想到的是 nvcc clang ),看看它们中的任何一个是否都同意语法,然后在对您很重要的情况下将其用于可移植性.

As you can se, the only difference is that -Wl allows you to specify multiple arguments by means of a comma, like -Wl,-rpath,/my/libs, which you cannot do with -Xlinker; on the other hand, -Xlinker is maybe a bit more self-descriptive. Take your pick. Also check other compilers (nvcc comes to mind, and clang) to see if any of them agree on the syntax, and then use that for portability if that's important to you.

这篇关于"-Wl,option"和"-Wl,option"之间有区别吗?和"-Xlinker选项"GCC的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆