xcode 如何获取 Mac 上可用的最新 SDK 的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18741675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:54:12  来源:igfitidea点击:

How to get the path of latest SDK available on Mac

xcodemacos

提问by Mircea Ispas

I know that in order to get xcode install directory from command line I have to use xcode-select -print-path. The result is something like: /Applications/Xcode.app/Contents/Developer

我知道为了从命令行获取 xcode 安装目录,我必须使用xcode-select -print-path. 结果是这样的:/Applications/Xcode.app/Contents/Developer

Is there any command to get latest SDK folder? I need as result something like: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/

是否有任何命令可以获取最新的 SDK 文件夹?我需要这样的结果:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/

If it's not possible to get the SDK complete path I need at least SDK number and I'll try to build the path.

如果无法获得 SDK 完整路径,我至少需要 SDK 编号,然后我会尝试构建路径。

采纳答案by Rob Napier

I'm sure this could be cleaned up a bit, and probably done in a single line of perl, but here's an easy approach:

我相信这可以稍微清理一下,并且可能在一行 perl 中完成,但这里有一个简单的方法:

sdkparam=`xcodebuild -showsdks | awk '/^$/{p=0};p; /OS X SDKs:/{p=1}' | tail -1 | cut -f3`
sdkpath=`xcodebuild -version $sdkparam Path`

The point of the awk is to print the "OS X SDKs" block from -showsdks. Then take the last line of it and the 3rd field (it's separated with tabs). Then we ask xcodebuildfor the path to that sdk.

awk 的重点是从-showsdks. 然后取它的最后一行和第三个字段(它用制表符分隔)。然后我们询问xcodebuild该sdk的路径。

回答by Ruslan Ulanov

The easiest way I found so far is:

到目前为止,我发现的最简单的方法是:

xcrun --show-sdk-path

回答by Sriram Murali

To be more precise,

更准确地说,

xcrun --sdk macosx --show-sdk-path