I have very strange errors with Xcode 3.2.6 and Xcode 4.
Xcode 3.2.5 does not have the errors in my proj开发者_如何学JAVAect.
Symbol hidden by defaults option is set to YES.
These link errors are related to static members (pointers) inside template classes. Any ideas, compiler/linker keys to check, anything?
This has to do with symbol visibility in the libraries you have compiled. The GCC 4.0 switch -fvisibility=hidden option is intended to hide symbols for DSO/shared object libraries to reduce link/load times. However, I have seen some blogs online using the switch in some peculiar manner when compiling static libraries. I haven't actually been able to find out what the effect or intent of this is. To the best of my knowledge, static libraries need symbol information exposed for functions you intend to use from the outside.
I experienced this same linker error with boost::exceptions. However, in order to catch exceptions of a particular type, GCC requires type information, but that is a run-time issue. Thus, even if it compiles/links correctly, hiding symbol information in your projects is not the correct solution if you intend to catch an exception from outside the library. See Apple's documentation:
If your symbol uses runtime type identification (RTTI) information, exceptions, or dynamic casts for an object that is defined in another library, your symbol must be visible if it expects to handle requests initiated by the other library. For example, if you define a catch handler for a type in the C++ standard library, and you want to catch exceptions of that type thrown by the C++ standard library, you must make sure that your typeinfo object is visible.
Source: http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html
I actually needed to modify the exception header with the macro guards described here to get my project to compile and link: http://gcc.gnu.org/wiki/Visibility. This was neccessary even with -fvisibility=default, which makes me believe this was some sort of linker bug.
Nevertheless, I logged a bug against Boost here: https://svn.boost.org/trac/boost/ticket/4594#comment:11
You can find my configuration here: http://lists.boost.org/boost-users/2011/07/69251.php
There is an answer here : "bad codegen, pointer diff" linker error with Xcode 4
精彩评论