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:
Please note:
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.
tl:dr; use -fvisibility=hidden
as a gcc and llvm compiler switch in everything you compile, including your dependent libraries, unless you have a reason not to.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With