XCode static link library with environment variable

I want to link a static library ( .a file) with my code with some limitations

  • The condition must be an environment variable instead of an assembly type (Debug, Release) or architecture.
  • If the static library is not used (not imported, not used in the code), then the final binary file should not contain any links to it.

The code should look like this:

 #ifdef CRASH_LOGGING [Crittercism enableWithAppID:@"abc"] #endif 

And the environment variable should have a similar name.

I played with OTHER_LINKER_FLAGS = -weak_library , removing .a from the target, setting it as optional, but I can't get it to work. Either the library is not connected, I get a compilation error, or the .a part belongs to the final executable.

How can i achieve this?

+4
source share
1 answer

In the end, I decided to solve this problem by adding more options to the xcodebuild command line.

Basically you need to configure:

  • Where are the .h header files
  • Where is the .a library
  • Tell the linker that you want to use the -lCrittercism_v4_0_7 library
  / usr / bin / xcodebuild -configuration Release clean
 "LIBRARY_SEARCH_PATHS = \ $ {LIBRARY_SEARCH_PATHS} \ $ {PROJECT_DIR} / Libraries / CrittercismSDK"
 "HEADER_SEARCH_PATHS = \ $ {HEADER_SEARCH_PATHS} \ $ {PROJECT_DIR} / Libraries / CrittercismSDK" 
 "OTHER_LDFLAGS = -lCrittercism_v4_0_7"

With this approach, you do not need to add the library to the target or to Xcode. If the last three parameters are not added to the command line, the library will not belong to the final executable file at all.

0
source

Source: https://habr.com/ru/post/1489436/


All Articles