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

标签 xcode macos ld

我们正在构建一个 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++ 库。我们正在链接这些库:

  1. libphonenumber ,这显然是导致 5 个警告中的 4 个的原因。由我们通过“cmake”编译。
  2. boost (libboost_thread-mt),负责 1 个警告。使用 MacPorts 编译。
  3. ICU(libicudata、libicuuc、libicui18n),使用 MacPorts 编译。
  4. Protocol Buffers ,通过“./configure && make”编译。

请注意:

  1. 尽管有警告,应用程序仍然运行良好,但我们希望摆脱它们,因为它们很烦人。
  2. 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/

相关文章:

macos - 对于macOS Cocoa,如何指定屏幕上的某个窗口或矩形进行截图?

linker - --unresolved-symbols=ignore-in-shared-libs 和 --allow-shlib-undefined 标志有什么区别

gcc/ld : undefined reference to unused function

xcode - 使用自制软件安装的 gcc 编译器时发生rails 4 gem 安装错误

arrays - Swift:2 个类似错误:无法使用 'x' 类型的参数列表调用 '(([xx]) -> ())'

c++ - 在 Mac OS X 上共享一个 c++ 库,这样我就可以将用户定义的函数添加到 mySQL

macos - Minikube 无法在 Mac 上使用 VPN 启动

c++ - g++ 在函数 __start 中链接到 crt1.o 时遇到 fatal error

xcode - NSUserDefault 不应该是单元测试的白板吗?

ios - 将 Xcode 6.3 重置为原始状态