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

蹲街弑〆低调 提交于 2019-12-08 16:23:04

问题


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:


  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.




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!