xcode 来自链接器的奇怪警告 (ld)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9894961/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:20:34  来源:igfitidea点击:

Strange warnings from the linker (ld)

xcodemacosld

提问by ItalyPaleAle

We are building a Mac OSX application which is written mostly in Obj-C/Cocoa. The application then statically links with some 3rd party libraries, written in C/C++ and compiled by us (on a command line, using either MacPorts or the usual "./configure && make"; all are universal binaries).

我们正在构建一个主要用 Obj-C/Cocoa 编写的 Mac OSX 应用程序。然后,该应用程序与一些用 C/C++ 编写并由我们编译的 3rd 方库静态链接(在命令行上,使用 MacPorts 或通常的“./configure && make”;所有都是通用二进制文件)。

The application is working perfectly, but ad compile time we are always getting these strange linker warnings:

该应用程序运行良好,但广告编译时我们总是收到这些奇怪的链接器警告:

ld: warning: direct access in ___cxx_global_var_init17 to global weak symbol __ZGVN4i18n12phonenumbers9SingletonINS0_15PhoneNumberUtilEE8instanceE means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
ld: warning: direct access in ___cxx_global_var_init17 to global weak symbol __ZGVN4i18n12phonenumbers9SingletonINS0_15PhoneNumberUtilEE8instanceE means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
ld: warning: direct access in ___cxx_global_var_init17 to global weak symbol __ZN5boost10scoped_ptrIN4i18n12phonenumbers15PhoneNumberUtilEED1Ev means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
ld: warning: direct access in ___cxx_global_var_init17 to global weak symbol __ZN4i18n12phonenumbers9SingletonINS0_15PhoneNumberUtilEE8instanceE means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.
ld: warning: direct access in ___cxx_global_var_init17 to global weak symbol __ZGVN4i18n12phonenumbers9SingletonINS0_15PhoneNumberUtilEE8instanceE means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

This comes from a C/C++ library. We are linking with these libs:

这来自 C/C++ 库。我们正在与这些库链接:

  1. libphonenumber, which is the one causing 4 of the 5 warnings, apparently. Compiled by us via "cmake".
  2. boost (libboost_thread-mt), responsible of 1 warning. Compiled with MacPorts.
  3. ICU (libicudata, libicuuc, libicui18n), compiled with MacPorts.
  4. Protocol Buffers, compiled via "./configure && make".
  1. libphonenumber,显然是导致 5 个警告中的 4 个的那个。我们通过“cmake”编译。
  2. boost (libboost_thread-mt),负责 1 个警告。用 MacPorts 编译。
  3. ICU (libicudata, libicuuc, libicui18n),用 MacPorts 编译。
  4. Protocol Buffers,通过“./configure && make”编译。

Please note:

请注意:

  1. The application is working perfectly despite the warnings, but we'd like to get rid of them as they are annoying.
  2. The solution proposed by xcode with boost : linker(Id) Warning about visibility settingsdoesn't work: "Symbols hidden by default" has always been "YES".
  1. 尽管有警告,该应用程序运行良好,但我们希望摆脱它们,因为它们很烦人。
  2. xcode提出的带有 boost的解决方案:linker(Id) 关于可见性设置的警告不起作用:“默认隐藏的符号”始终为“是”。

采纳答案by inspector-g

The solution proposed by xcode with boost : linker(Id) Warning about visibility settings doesn't work: "Symbols hidden by default" has always been "YES".

xcode 提出的带有 boost 的解决方案:linker(Id) 关于可见性设置的警告不起作用:“默认隐藏的符号”始终为“是”。

This has less to do with being set to "YES", and more to do with being set to the same value across all projects. Libs/projects that depend on other libs need to have a likewise setting for "Symbols hidden by default" in order to link properly and free of errors/warnings.

这与设置为“YES”的关系不大,而与在所有项目中设置为相同的值有关。依赖于其他库的库/项目需要对“默认隐藏的符号”进行类似的设置,以便正确链接并且没有错误/警告。

I've run into this before, and a simple change in Xcode for all projects to ensure the settings match typically resolves the problem. Since it sounds like you're compiling on the command line as well, the -fvisibilityargument to gccis what you need to look at.

我以前遇到过这种情况,并且对所有项目在 Xcode 中进行简单更改以确保设置匹配通常可以解决问题。由于听起来您也在命令行上进行编译,因此您需要查看-fvisibility参数 to gcc

回答by johnwbyrd

tl:dr; use -fvisibility=hiddenas a gcc and llvm compiler switch in everything you compile, includingyour dependent libraries, unless you have a reason not to.

tl:博士;用-fvisibility=hidden在一切编译,一个GCC和LLVM编译器开关,包括你的依赖库,除非你有充分的理由不这样做。

A good introduction to the -fvisibility and -fvisibility-inline-hidden compilation flags is available on Apple's web site, as of this writing. The article also goes into some detail on the __attribute__((visibility("hidden")))and __attribute__((visibility("default")))declarations.

在撰写本文时,Apple 网站上提供了对 -fvisibility 和 -fvisibility-inline-hidden 编译标志的很好的介绍。本文还详细介绍了__attribute__((visibility("hidden")))__attribute__((visibility("default")))声明。

回答by guest2016

I got the warning gone in Xcode by putting -fvisibility=hidden -fvisibility-inlines-hiddeninto OTHER C++ FLAGS.

通过放入-fvisibility=hidden -fvisibility-inlines-hiddenOTHER C++ FLAGS,我在 Xcode 中得到了警告。

回答by Nick

I also got this, for similar reasons, but I think the problem was inconsistency of the inlining visibility settings.

由于类似的原因,我也得到了这个,但我认为问题在于内联可见性设置的不一致。

See http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-December/046505.html

http://lists.cs.uiuc.edu/pipermail/llvmdev/2011-December/046505.html

I set all inlining hidden to no and the warning (finally) went away.

我将所有内联设置为 no,警告(终于)消失了。