如何让g ++使用-z multidefs 47 [英] How to allow -z multidefs with g++47

查看:471
本文介绍了如何让g ++使用-z multidefs 47的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



< blockquote>

-z multidefs允许多个符号定义。默认情况下,在可重定位对象(.o文件)
之间发生的多个符号定义将导致致命错误情况。此选项可以抑制
错误条件,并允许采用第一个符号定义。
此选项仅在指定-b svr4选项时有效。


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

解决方案

没有像g ++的链接器那样的东西,它使用您的系统自己的链接器。 / p>

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


-Xlinker选项

选项作为选项传递给链接器。您可以使用它来提供GCC不知道如何识别的特定于系统的链接器选项。

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

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



-Wl,option <
作为链接器的一个选项,传递选项。如果选项包含逗号,则逗号分成多个选项。您可以使用此语法将
参数传递给选项。例如, -Wl,-Map,output.map -Map output.map 传递给链接器。当使用GNU链接器时,您还可以通过 -Wl,-Map = output.map 获得
的相同效果。


所以你可以使用

  -Xlinker -z -Xlinker multidefs 

  -Wl,-z,multidefs 

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

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

编辑:从您的评论中我看到您使用的是Mac OS X,它使用达尔文链接器,其手册页显示相应的选项已过时:


-m 不要将多个定义视为错误。这不再支持。此选项已过时。



How can I tell the linker of g++ to allow multiple definitions of symbols (choose the first appearance)?

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

The -zmuldefs option is not recognized by g++, nor -z OPTION. What's the correct parameter? Is it possible?

解决方案

There is no such thing as the "linker of g++", it uses your system's own linker.

To pass options through from GCC to the linker you need to use GCC's -Wl, or -Xlinker options:

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

So you would want to use

-Xlinker -z -Xlinker multidefs

or

-Wl,-z,multidefs

but the docs you quoted say you must also use -b svr4 to use that option, e.g.

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

Edit: From your comments I see you're on Mac OS X, which uses the darwin linker, and its man page shows the corresponding option is obsolete:

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

这篇关于如何让g ++使用-z multidefs 47的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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