问题
For example, if I need Gtk+ include paths.
How to use pkg-config gtk+-2.0 --cflags
in Xcode project settings?
回答1:
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.
回答2:
- Create an aggregate target
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
In Info in your project, set MyApp.xcconfig as your target configuration file
- In Build Phases in your app target, add the aggregate target as a dependency
- 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.
回答3:
More portable would be to write a script that writes the output of pkg-config into an .xcconfig file and then include that in your project. Just be sure to not add it into your source repository.
回答4:
- Use a makefile that uses pkg-config and any other shell tools to build a lib.
Create a small, dependency-free API file for the lib that will compile in XCode, and include it and the built lib in the XCode build.
Optional: encapsulate the makefile build into a "Run Script" build step in XCode.
来源:https://stackoverflow.com/questions/3071321/how-to-use-pkg-config-for-setting-include-paths-in-xcode