加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – DEVELOPER_DIR是否需要在环境中保持设置?

发布时间:2020-12-14 19:38:03 所属栏目:百科 来源:网络整理
导读:我想并排安装XCode,并使用DEVELOPER_DIR环境变量在它们之间进行选择.这样做的目的是使用xcrun -f –sdk macosx clang的结果来确定适当的C编译器,然后在脚本或构建系统中使用它. CC = $(DEVELOPER_DIR = something xcrun -f –sdk macosx clang) 我的问题是在
我想并排安装XCode,并使用DEVELOPER_DIR环境变量在它们之间进行选择.这样做的目的是使用xcrun -f –sdk macosx clang的结果来确定适当的C编译器,然后在脚本或构建系统中使用它.

CC = $(DEVELOPER_DIR =< something> xcrun -f –sdk macosx clang)

我的问题是在使用xcrun找到的工具时是否需要保持DEVELOPER_DIR设置,或者是否可以在执行xcrun期间设置它,如上所述,然后在默认环境中使用返回的工具,而不使用DEVELOPER_DIR仍然设定.

换句话说,虽然xcrun显然取决于DEVELOPER_DIR的值,但这些工具本身也依赖于它吗?两者之间有什么有意义的区别:

> DEVELOPER_DIR =< whatever>命令CC = $(xcrun -f –sdk macosx clang)
>命令CC = $(DEVELOPER_DIR =< whatever> xcrun -f –sdk macosx clang)

第二个是正确的吗?还是只有第一个?

解决方法

I’d like to have side-by-side installations of XCode,and use the DEVELOPER_DIR environment variable to select between them.

安装两个或更多版本的Xcode很好.在它们之间进行选择的常用方法是使用xcode-select命令,但该命令的手册页似乎确实表明您可以通过自己设置DEVELOPER_DIR环境变量来完成当前会话的相同操作.以下是–switch选项的文档说明:

Sets the active developer directory to the given path,for example
/Applications/Xcode-DP.app. This command must be run with superuser
permissions (see sudo(8)),and will affect all users on the system. To
set the path with-out superuser permissions or only for the current
shell session,use the DEVELOPER_DIR environment variable instead
(see ENVIRONMENT).

但是,您还应该注意环境部分中给出的建议:

Note that for historical reason,the developer directory is considered
to be the Developer content directory inside the Xcode application
(for example /Applications/Xcode.app/Contents/Developer). You can set
the environment variable to either the actual Developer contents
directory,or the Xcode application directory — the code-select
provided shims will automatically convert the environment variable
into the full Developer content path.

那么< what>在您的问题中应该指定Developer目录的完整路径,而不仅仅是Xcode应用程序.

In other words,while xcrun clearly does depend on the value of DEVELOPER_DIR,do the tools themselves depend on it too? Is there a meaningful difference between:

? DEVELOPER_DIR=<whatever> command CC=$(xcrun -f --sdk macosx clang)

使用xcrun查找工具,以便您可以自己调用它们并担心何时设置和取消设置DEVELOPER_DIR似乎过于复杂.根据xcode-select文档,所有“垫片”都遵循DEVELOPER_DIR设置.这里的“Shims”是指/usr/bin中的Xcode命令.只要正确设置了该环境变量,就可以调用’/usr/bin/clang’而不是xcrun找到的任何内容,而/usr/bin/clang将调用DEVELOPER_DIR中的clang版本.据推测,你问这个问题是因为你正在编写某种类型的构建脚本,所以在该脚本中尽早设置DEVELOPER_DIR然后只使用/usr/bin命令应该没有问题.

? command CC=$(DEVELOPER_DIR=<whatever> xcrun -f --sdk macosx clang)

程序从其父进程继承环境.在这里,您要找到要使用的clang的正确副本,但是您将在未设置DEVELOPER_DIR的环境中调用它.这是否重要取决于您使用的工具是否调用任何其他工具.老实说,我不知道是否有任何工具会调用其他工具,但像xcodebuild这样的工具会调用许多这些工具,因此依赖于DEVELOPER_DIR正确设置似乎是合乎逻辑的.

简而言之,在构建脚本中根据需要设置DEVELOPER_DIR没有任何缺点,并且仅在调用xcrun时尝试指定它似乎比替代方法更不可靠.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读