To hide symbols or not to hide symbols
To hide symbols or not to hide symbols
- Subject: To hide symbols or not to hide symbols
- From: Nir Soffer <email@hidden>
- Date: Fri, 22 Dec 2006 01:18:03 +0200
I found an annoying problem with globals and dependent unittest
targets. If you export some constants, for example notifications
names, those constants are not accessible to dependent unittest target.
To reproduce the problem, add this these files to a Cocoa application
project:
// MyApp.h
extern NSString *MyName;
// MyApp.m
NSString *MyName = @"Foo";
Now create a new dependent test target, and reference MyName in a
test. When you build the test target, you will get this linker error:
/usr/bin/ld: Undefined symbols:
_MyName
A similar issue is described here: http://www.dribin.org/dave/blog/
archives/2006/01/20/test_bundle_2/
After a lot of searching I found the problem - there is a new setting
in GCC 4 (GCC_SYMBOLS_PRIVATE_EXTERN, -fvisibility=hidden) that hides
all symbols that are not explicitly marked as visible. See file:///
Developer/ADC Reference Library/documentation/DeveloperTools/
Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html
A new Cocoa application created with Xcode 2.4 has "Symbols are
Hidden by Default" checked. The setting is in the Code Generation
page of the target build settings. Dependent unit test target will
not be able to access globals by default.
There are several solutions to enable dependent unittest targets:
1. Disabled the "Symbols are Hidden by Default" for the application
target
2. Disable the setting only for the Debug configuration, used to run
the tests
3. Mark the needed symbols as visible (e.g. __attribute__((visibility
("default"))) extern MyName;)
I think the best solution is 2, because I don't want to export
anything in the application, except when running the unittests.
However, I like to test the same code that the user run, to minimize
the risk of hidden bugs that show only in the release version.
I would like to hear your opinion on this issue.
Best Regards,
Nir Soffer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden