XCode无法识别环境变量 [英] XCode doesn't recognize environment variables

查看:220
本文介绍了XCode无法识别环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下脚本在OSX Yosemite 10.10.5上运行XCode(7.0.1 7A1001):

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

然后,我打开一个包含两个项目的工作区: App1 App2 .在两个项目中,我都将$(HOME)/$(FOO)放在 Header Search Paths 字段中.

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

  • App1 中,按预期将其解析为/Users/ohads/bar.
  • App2 中,它解析为/Users/ohads/-请注意如何解析HOME变量,但不能解析FOO变量.
  • 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.

这是怎么回事?为什么会有差异?如何使FOO在App2中工作-我缺少一些特殊的标志或声明吗?

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?

顺便说一句,似乎还不够怪异,即使我仅使用export,App1仍然可以工作(与launchctl相对,后者应该用于GUI应用程序,因为export应该只影响现金应用程序)

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).

推荐答案

看起来与

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

发出此命令后,exportlaunchctl均起作用(根据chepner的评论).我只能猜测它是在 App1 中工作的,因为它是在较旧的XCode版本中创建的.

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.

这篇关于XCode无法识别环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆