将Apple Clang版本还原为NVCC适用的版本

32

我正在尝试在我的Mac上运行NVCC以编译CUDA程序。

当我尝试运行NVCC时,我收到以下错误消息:"nvcc fatal : The version ('70300') of the host compiler ('Apple clang') is not supported"。

最近我将XCode版本更新到了7.3,并将我的Mac更新到了10.11.4。

有没有办法恢复我的Clang版本呢?


3
更新:CUDA 7.5.27已发布。它现在可以在Mac OS 10.11.4上使用Apple LLVM版本7.3.0(clang-703.0.29)。 - Daniel Trebbien
5
不适用于新的Xcode 8版本。 - Georg Heiler
@GeorgHeiler 这个对我很有帮助:https://github.com/caffe2/caffe2/issues/318#issuecomment-295555763 - Peter Becich
9个回答

46

谢谢!顺便说一下,如果您已经升级到8.0,那么您不需要执行步骤(1),只需在此运行第二个命令即可。这将使我的clang版本升级到7.3,现在一切正常。 - ComputerScientist
这个“方法”虽然有效,但我的cutorch安装仍然失败了。我错过的是我仍然有缓存版本挂在那里。在我的情况下,我没有运行make clean/clean.sh。 感谢github上的subzerofun - https://github.com/torch/cutorch/issues/522#issuecomment-252517776 - Ivar
这在我的Mac 10.12.5(Sierra)上运行良好。 CMT 7.3链接谢谢 - dgmz
1
你怎么切换回去呢 :) - SumNeuron
这个revert操作只是针对这种特定情况,它并没有切换到特定版本。你能提供一个更通用的解决方案吗? - Chris

9
接受的答案建议下载次新版本的命令行工具并安装,然后通过在控制台中输入来选择它们。
sudo xcode-select --switch /Library/Developer/CommandLineTools

有人问如何恢复工具的原始版本。这可以通过以下方式实现:

sudo xcode-select --switch /Applications/Xcode.app

7
我刚升级到10.11上的XCode 7.3,遇到了同样的问题。重新安装之前的(7.2)命令行工具没有降级默认的clang编译器。为了解决这个问题,我使用了一个旧的XCode.app包将XcodeDefault.xctoolchain目录重命名并复制到当前/Applications/Xcode.app的Toolchains目录中。你需要右键单击Xcode.app来“显示包内容”,然后浏览到Toolchains目录。

enter image description here

然后重新启动Xcode,按下Command-,打开偏好设置,然后进入位置。您将看到“命令行工具”的下拉菜单。将其更改为您复制过来的工具链版本。

enter image description here

你可以在终端中检查clang的默认版本:
clang -v OR llvm-gcc -v

现在nvcc应该可以工作了


1
请问您上一个xCode.app是从哪里获取的?当我从苹果网站下载时,它是一个安装包,但我不想在我的系统上安装它。 - Anatoliy Kmetyuk
1
登录您的苹果开发者账户,然后点击此链接:https://developer.apple.com/downloads/。该网站提供了旧版Xcode的DMG文件下载。至少可以下载到6.4版本,其中包含Xcode.app文件。 - adon
是的,谢谢,我已经想到了。我试图作弊并只下载命令行工具,但它们是可安装包,所以我无法从中提取clang。 - Anatoliy Kmetyuk

4

当我点击这个页面时,它说找不到。是否有更新的页面? - Jude Michael Murphy
@JudeMichaelMurphy 看起来您需要通过 https://developer.apple.com/downloads/ 使用苹果开发者帐户登录。 - fabregaszy

1
我会尝试使用homebrew的llvm版本,这对我很有效。 brew install llvm37 然后将编译器设置为homebrew的clang: /usr/local/bin/clang++-3.7 或者是响应 which clang++-3.7 这样你就可以保留OS X开发环境的默认设置。

你如何将编译器设置为Homebrew的Clang?我尝试将/usr/local/bin放在PATH的最前面,并设置ln -s clang++-3.7 clang,但是我仍然得到相同的错误。 - Jonathan Mugan
1
我不会使用brew进行硬链接,这样做非常混乱。请更改您的“configure”或“cmake”变量以使用Cellar中的编译器。我的clang路径为/usr/local/Cellar/llvm37/3.7.1/bin/clang++-3.7。CMAKE_CXX_COMPILER和CUDA_HOST_COMPILER是cmake的常见变量。 - Dave Braford-Grimes
1
ln -s clang++-3.7 clang 只是将 "clang++-3.7" 指向 "clang",对你没有任何好处。链接是从源到目标,而不是反过来。此外,您的链接可以是相对或绝对的 - 我更喜欢绝对的,但在这种情况下不会使用符号链接。 - Dave Braford-Grimes
这是唯一明智的答案,它应该有更多的赞同。 - Miguel Monteiro

1

不幸的是,从X-code版本7.2安装命令行工具目前无法解决此问题。

尝试编译会导致:

nvcc fatal : GNU C/C++编译器在Mac OS X上不再支持作为主机编译器。

对我有用的方法是卸载Xcode 7.3并从Apple开发者网站安装Xcode 6.2。


2
这是你的答案还是另一个问题? - hering
用我找到的解决方案替换了问题。谢谢。 - Jörg

1

奇怪的是这对我起作用了。我的电脑上有几个版本的Xcode,但我需要将原始版本重命名,以便xcode-select命令实际选择旧的编译器。 - Derwent

1

80100可以与一些nvcc程序一起使用

我使用"80100"和nvcc为我的其他一些程序工作。

...但不适用于示例

`

...
nvcc fatal   : The version ('80100') of the host compiler ('Apple clang') is not supported
...

`

安装CLT 8.2(来自苹果的命令行工具),它与“命令行工具实例”的消息有点相关

我搜索并看到了关于此问题的讨论(https://github.com/arrayfire/arrayfire/issues/1384关于array fire nvcc问题的讨论,并且由于提示切换到CLT 8.2,最后一个版本而不是当前版本。这有点可以接受,但会出现关于“命令行工具实例”的警告消息。

需要使用“sudo make”编译示例代码:

` ... $ sudo make Password:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
expr: syntax error

/Developer/NVIDIA/CUDA-8.0/bin/nvcc -ccbin g++ -I../../common/inc  -m64  -Xcompiler -arch -Xcompiler x86_64  -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o deviceQuery.o -c deviceQuery.cpp

nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).

/Developer/NVIDIA/CUDA-8.0/bin/nvcc -ccbin g++   -m64  -Xcompiler -arch -Xcompiler x86_64  -Xlinker -rpath -Xlinker /Developer/NVIDIA/CUDA-8.0/lib  -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_60,code=compute_60 -o deviceQuery deviceQuery.o 

nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).

mkdir -p ../../bin/x86_64/darwin/release

cp deviceQuery ../../bin/x86_64/darwin/release

$ ./deviceQuery
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)
...

`


nvcc致命错误:主机编译器(“Apple clang”)的版本(“80100”)不受支持。我在OS X 10.12.4,Xcode 8.3编译第三方库(PCL)时也遇到了这个错误。有人知道任何解决方法吗?我已经尝试过不同版本的CLT。 - AlexeyIS

0
我曾经遇到过同样的问题! 在我的Time Machine备份中查找并复制Xcode.app(7.2.1)到我的/Application文件夹中。您也可以从Apple Developer页面下载它并将其移动到/Application文件夹中。 完成后,您可以在Xcode的首选项中更改Xcode命令行版本为7.2.1 然后nvcc将再次工作(即使使用pycuda-2016.1)。
clang --version
给了我:
Apple LLVM版本7.0.2(clang-700.1.81)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接