我想在OSX山狮中编译一个c文件。在Xcode 4.4,Preferences ->下载中,我可以安装命令行工具来实现这一点。然而,在该窗格中,它建议我可以使用xcrun代替:
在安装之前,请注意,在终端内部,您可以使用XCRUN工具启动编译器和嵌入在Xcode应用程序中的其他工具。使用XCODE-SELECT工具来定义Xcode的哪个版本是活动的。从终端输入"man“以查找更多信息。
我很乐意那样做,但我很难让它找到stdio.h。
$ xcrun gcc hello.c
hello.c:1:19: error: stdio.h: No such file or directory在通过App : /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/stdio.h标准安装Xcode之后,我的系统上肯定有这个文件
我尝试指定SDK,但得到了相同的错误:
$ xcrun -sdk /Applications/Xcode.app/Contents/Developer//Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk gcc hello.c一些谷歌让我尝试在上面的命令之前运行xcode-select,但没有成功。无论如何,我只安装了一个版本的Xcode。
$ sudo xcode-select -switch /Applications/Xcode.app我怎样才能让它找到标题?
最后,我放弃并安装了命令行工具,但是知道如何使用内置的Xcode工具是很好的。
注意:下面是我试图编译的文件:
#include <stdio.h>
int main() {
printf("hello world!\n");
return 0;
}发布于 2012-08-19 08:45:18
您必须为编译器指定非标准的sysroot。
使用clang/llvm (这是新的标准)可以完成以下任务:
xcrun clang --sysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/ -o hello hello.c 如果你想和gcc呆在一起,只需将"clang“改为"gcc”即可。
发布于 2012-08-26 06:18:16
这方面可能没有任何直接帮助,但您可以将别名设置为常用的xcrun命令,以便在其他进程调用gcc、make、gdb、git等进程时使用Xcode版本:
alias gcc='xcrun gcc'如果您愿意,可以将别名放入.bashrc文件中,这样它就会持久存在,并在必要时从.bash_profile获得源。
所有这些的优点在于,您不需要安装Xcode命令行工具,也可以避免使用包管理器,节省空间,降低复杂性,并利用Xcode自动更新这些工具。
发布于 2013-11-09 07:45:40
使用xcrun -sysroot并不适合我使用10.8。查看clang文档,我发现-isysroot是在本例中使用的选项。
使用:
xcrun gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk或者:
xcrun clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk对我来说,创建以下别名是有用的:
alias xcrungcc='xcrun gcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk'
alias xcrunclang='xcrun clang -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk'https://stackoverflow.com/questions/11838993
复制相似问题