Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - Modify Library Search Path Based on device which code is being compiled for

I am sure this has been asked before, however I have been banging my head against a brick wall all afternoon trying to figure out how to achieve this using XCode 4.

I have a lib which was distributed by a 3rd party. They actually ship 2 different versions, one for use in the simulator, and one for use with the actual device.

I would like to know, what is the recommended way for handling situations like this in XCode 4; in XCode 3, I could simply have specified a new target. I wish to avoid creating a fat binary via lipo containing both libs, but if that is the only feasible option available to me, then so be it.

Ideally what I would like to do is modify the Library Search path based upon the current device the project is being compiled for such as:

Simulator: /path/to/simulator/lib.a

Device /path/to/device/lib.a

If I could automate the process so once I had set it up, it was transparent, all the better.

Many thanks for taking the time to read this.

like image 948
Mick Walker Avatar asked Mar 30 '11 21:03

Mick Walker


People also ask

Where is library search path in Xcode?

The libraries will be located under lib .

What is Srcroot?

$(SRCROOT) (aka $(SOURCE_ROOT) ) is a path to your location where a .

What is Built_products_dir?

BUILT_PRODUCTS_DIR. Description: Directory path. Identifies the directory under which all the product's files can be found. This directory contains either product files or symbolic links to them.


1 Answers

XCode define $(EFFECTIVE_PLATFORM_NAME) to be 'iphoneos' or 'iphonesimulator' base on the target "device". As long as your library path includes one of those strings, you can set LIBRARY_SEARCH_PATHS in your targets or project to something like:

/path/to/$(EFFECTIVE_PLATFORM_NAME)/lib.a

Hint: you can see this in action by clicking "All" in Building Settings, and then selecting Editor > Show Setting Names and Editor > Show Setting Definitions in the menus. To see if the final value is what you expect, switch back to values using Editor > Show Setting Values.

like image 111
Yair Avatar answered Oct 03 '22 17:10

Yair