gpt4 book ai didi

c++ - 如何使用 g++47 允许 -z multidefs

转载 作者:行者123 更新时间:2023-11-30 00:53:05 28 4
gpt4 key购买 nike

如何告诉 g++ 的链接器允许多个符号定义(选择第一个出现的)?

-z multidefs Allows multiple symbol definitions. By default, multiple symbol definitions occurring between relocatable objects (.o files) will result in a fatal error condition. This option suppresses the error condition and allows the first symbol definition to be taken. This option is valid only when the -b svr4 option is specified.

-zmuldefs 选项无法被 g++ 识别,-z OPTION 也无法识别。什么是正确的参数?可能吗?

最佳答案

没有所谓的“g++的链接器”,它使用你系统自己的链接器。

要将选项从 GCC 传递到链接器,您需要使用 GCC 的 -Wl,-Xlinker 选项:

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

所以你会想要使用

-Xlinker -z -Xlinker multidefs

-Wl,-z,multidefs

但是您引用的文档说您还必须使用 -b svr4 才能使用该选项,例如

-Wl,-b,svr4,-z,multidefs

编辑:从您的评论中我看到您使用的是 Mac OS X,它使用 darwin 链接器及其 man page显示相应的选项已过时:

-m Don't treat multiple definitions as an error. This is no longer supported. This option is obsolete.

关于c++ - 如何使用 g++47 允许 -z multidefs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17443976/

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