XCode doesn't recognize environment variables

核能气质少年 提交于 2020-01-01 15:34:06

问题


I use the following script to run XCode (7.0.1 7A1001) on OSX Yosemite 10.10.5:

export FOO=bar #this should not be necessary, but just in case
launchctl setenv FOO bar #should make it visible to all GUI applications (=XCode)
open -a xcode

I then open a workspace with two projects: App1 and App2. In both projects I put $(HOME)/$(FOO) in the Header Search Paths field.

  • In App1 it is resolved to /Users/ohads/bar as expected.
  • In App2 it is resolved to /Users/ohads/ - note how the HOME variable is resolved, but the FOO variable is not.

What's going on here? Why the discrepancy? How can I make FOO work in App2 - is there some special flag or declaration I'm missing?

BTW, as if that's not weird enough, App1 works even when I only use export (as opposed to launchctl which is what one should use for GUI applications, seeing as export should only affect cash applications).


回答1:


Looks like this has to do with new XCode 7 behavior. In order for XCode to use environment variables the following command must be issued:

$ defaults write com.apple.dt.Xcode UseSanitizedBuildSystemEnvironment -bool NO

Once this command is issued, both export and launchctl work (as per chepner's comment). I can only guess it was working in App1 because it was created in an older XCode version.



来源:https://stackoverflow.com/questions/33235958/xcode-doesnt-recognize-environment-variables

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