views:

152

answers:

1

I'm trying to condtionally link in. .a static libraries by defines. Is this possible in xcode? Basically trying to wrap library specific code in ifdefs so it can be excluded at compile time by setting flags.

+1  A: 

No, a C #define is not at the same level as library linkage.

However, you can set a C #define (via the Preprocessor Macros build setting) from the value of a custom build setting, like BUILT_WITH_FOO, and also set your OTHER_LDFLAGS build setting based on that custom build setting as well.

For example:

BUILT_WITH_FOO = foo

GCC_PREPROCESSOR_DEFINITIONS_ = USING_FOO=0
GCC_PREPROCESSOR_DEFINITIONS_foo = USING_FOO=1
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_$(BUILT_WITH_FOO))

OTHER_LDFLAGS_ = -lsomething
OTHER_LDFLAGS_foo = -lsomething -lfoo
OTHER_LDFLAGS = $(OTHER_LDFLAGS_$(BUILT_WITH_FOO))

The above would let you adjust only the value of the BUILT_WITH_FOO build setting to choose whether to use the Preprocessor Macros and Other Linker Flags variants whose names end with a trailing _, or the ones whose names end with a trailing _foo.

Chris Hanson
But would this solve my problem? Or if I have lib.a in my search paths but no code referencing it at compile time its nit compiled in at all anyway?
drunknbass
Chris Hanson