链接器发出的奇怪警告(ld) [英] Strange warnings from the linker (ld)

查看:229
本文介绍了链接器发出的奇怪警告(ld)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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. 协议缓冲区,通过"./configure&&make"进行编译.

请注意:

  1. 尽管有警告,该应用程序仍能正常运行,但我们希望摆脱它们,因为它们很烦人.
  2. xcode with boost提出的解决方案:linker(Id)警告关于可见性设置不起作用:默认情况下隐藏的符号"始终为是".

解决方案

xcode使用boost提出的解决方案:linker(Id)警告 可见性设置不起作用:默认情况下隐藏的符号"具有 一直是是".

这与设置为"YES"的关系较小,而与在所有项目中将其设置为相同的值关系较大.依赖于其他库的库/项目也需要对默认情况下隐藏的符号"进行同样的设置,以便正确链接且没有错误/警告.

我以前遇到过这个问题,并且对所有项目进行简单的Xcode更改以确保设置匹配通常可以解决问题.由于听起来也像在命令行上进行编译,因此需要查看gcc-fvisibility自变量.

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

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:

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

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 settings doesn't work: "Symbols hidden by default" has always been "YES".

解决方案

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

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.

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 -fvisibility argument to gcc is what you need to look at.

这篇关于链接器发出的奇怪警告(ld)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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