Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - linking binary with debug and release libraries

I have a project in Xcode 5 that uses various boost libraries. I have built both debug and release versions of boost and put the binaries in the same location.

I would like to build my application for debug and release in such a way that when I build a debug version it links to the debug boost libraries and when I build a release version it links to the release boost libraries.

In Xcode, under Build Phases, I don't see how to specify a set of binaries in 'Link binary With Libraries' for debug and another set for release.

How do I do this?

like image 973
ksl Avatar asked Apr 03 '14 07:04

ksl


1 Answers

In order to do that, you need to go into your target's "Build Settings" pane, find the "Other Linker Flags" setting, open the setting details by clicking on the arrow on the left side, and put different values in the "Debug" and "Release" lines.
The syntax for the option you want is -l<library name without "lib" prefix or extension>, so for instance:

  • -lboost_serialization-mt in the Release setting will link with libboost_serialization-mt.dylib
  • -lboost_serialization-mtd in the Debug setting will link with libboost_serialization-mtd.dylib

You may need to also tell it where your libraries are located, using -L</path/to/your/boost/libs> in the same setting, e.g. -L/opt/local/lib/

You probably also need to remove boost libraries from the "Link binary With Libraries" phase altogether.

You can also bypass the GUI for this by using .xcconfig settings files. See This question for details.

like image 157
Martin J. Avatar answered Sep 27 '22 20:09

Martin J.