我们正在构建一个 Mac OSX 应用程序,该应用程序主要是用 Obj-C/Cocoa 编写的。 然后,该应用程序静态链接到一些用 C/C++ 编写并由我们编译的第三方库(在命令行上,使用 MacPorts 或通常的“./configure && make”;所有都是通用二进制文件)。
应用程序运行完美,但在编译时我们总是收到这些奇怪的链接器警告:
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.
这来自 C/C++ 库。我们正在链接这些库:
- libphonenumber ,这显然是导致 5 个警告中的 4 个的原因。由我们通过“cmake”编译。
- boost (libboost_thread-mt),负责 1 个警告。使用 MacPorts 编译。
- ICU(libicudata、libicuuc、libicui18n),使用 MacPorts 编译。
- Protocol Buffers ,通过“./configure && make”编译。
请注意:
- 尽管有警告,应用程序仍然运行良好,但我们希望摆脱它们,因为它们很烦人。
- xcode with boost : linker(Id) Warning about visibility settings提出的解决方案不起作用:“默认隐藏符号”始终为"is"。
最佳答案
The solution proposed by xcode with boost : linker(Id) Warning about visibility settings doesn't work: "Symbols hidden by default" has always been "YES".
这与设置为“YES”关系不大,而与在所有项目中设置为相同值关系更大。依赖于其他库的库/项目需要有一个类似的“默认隐藏符号”设置,以便正确链接并且没有错误/警告。
我以前遇到过这个问题,对所有项目的 Xcode 进行简单更改以确保设置匹配通常可以解决问题。由于听起来您也在命令行上进行编译,因此您需要查看 gcc
的 -fvisibility
参数。
关于xcode - 来自链接器的奇怪警告(ld),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9894961/