gcc“-Xlinker”和“-Wl”选项之间的区别?

Difference between gcc "-Xlinker" and "-Wl," options?

根据 GCC 6.1 manual on Link Options:

-Wl, option

Pass option as an option to the linker. If option contains commas, it is split into multiple options at the commas.

-Xlinker option

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

为什么我们需要其中的 2 个?

加 1

同样,为什么我们需要 -Xassembler-Wa 作为汇编选项?

引自GCC 6.1 doc on Assembler Options

-Wa,option

Pass option as an option to the assembler. If option contains commas, it is split into multiple options at the commas.

-Xassembler option

Pass option as an option to the assembler. You can use this to supply system-specific assembler options that GCC does not recognize.

区别在于下面的粗体字

-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.

-Xlinker option

Pass option as an option to the linker. You can use this to supply system-specific linker options that GCC does not 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.

由于向后兼容,我想还有 2 个类似的功能。