Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use pkg-config for setting include paths in Xcode?

For example, if I need Gtk+ include paths. How to use pkg-config gtk+-2.0 --cflags in Xcode project settings?

like image 644
shoumikhin Avatar asked Jun 18 '10 16:06

shoumikhin


2 Answers

One option, but it's not very portable to other developers on the project -- you can just run pkg-config gtk+-2.0 --cflags in your Terminal and paste it into Build Settings -> Other C Flags. I'd be interested to hear how others deal with this in a more portable way though. Ideally, it would be nice to have pkg-config run at compile-time to make building more system-independent.

like image 112
Lytol Avatar answered Nov 06 '22 18:11

Lytol


  1. Create an aggregate target
  2. In Build Phases, add a Run Script

    #!/bin/bash
    
    OTHER_CPLUSPLUSFLAGS="$(pkg-config gtk+-2.0 --cflags)"
    echo -e "OTHER_CPLUSPLUSFLAGS = \$(inherited) ${OTHER_CPLUSPLUSFLAGS}" > MyApp.xcconfig
    
  3. In Info in your project, set MyApp.xcconfig as your target configuration file

  4. In Build Phases in your app target, add the aggregate target as a dependency
  5. Exclude MyApp.xcconfig in your version control

One drawback is that until you build the aggregate target directly or indirectly at least once, the autocomplete will not work properly.

like image 40
keithyip Avatar answered Nov 06 '22 18:11

keithyip