CUDA 编程和 xCode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11632919/
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
CUDA Programming and xCode
提问by Pierre-Luc Delisle
I'm completely new to Mac OS X and the main reason why I bought my new MacBook Pro R15 Retina Edition is to start studying CUDA API.
我对 Mac OS X 完全陌生,我购买新 MacBook Pro R15 Retina Edition 的主要原因是开始学习 CUDA API。
But I can't get my project build.
但是我无法构建我的项目。
For example, when I create a new CUDA project, I go in the project properties and make the following changes :
例如,当我创建一个新的 CUDA 项目时,我进入项目属性并进行以下更改:
Compiler for C/C++/Objective-C : LLVM GCC 4.2
C/C++/Objective-C 编译器:LLVM GCC 4.2
Other Linker Flag : -lcuda, -lcudart
其他链接器标志:-lcuda、-lcudart
Header Search Path : /usr/local/cuda/include
标题搜索路径:/usr/local/cuda/include
Library Search Path : /usr/local/cuda/lib
库搜索路径:/usr/local/cuda/lib
When I start adding the necessary libraries in my code, everything runs fine. My code gets no typing error.
当我开始在我的代码中添加必要的库时,一切都运行良好。我的代码没有打字错误。
When I build the project, I get linking errors (paths shortened and message broken up for readability):
当我构建项目时,我收到链接错误(路径缩短并且消息分解以提高可读性):
Ld /my_test_project/Build/Products/Debug/test normal x86_64 cd /Users/Admin/Documents/test setenv MACOSX_DEPLOYMENT_TARGET 10.7 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
-L/my_test_project/Build/Products/Debug
-L/usr/local/cuda/lib -F/my_test_project/Build/Products/Debug
-filelist /my_test_project/Build/Intermediates/test.build/Debug/test.build/Objects-normal/x86_64/test.LinkFileList
-mmacosx-version-min=10.7
-lcudart
-lcuda
-o /my_test_project/Build/Products/Debug/test
ld: file not found: @rpath/CUDA.framework/Versions/A/CUDA for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Ld /my_test_project/Build/Products/Debug/test normal x86_64 cd /Users/Admin/Documents/test setenv MACOSX_DEPLOYMENT_TARGET 10.7 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
-arch x86_64
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk
-L/my_test_project/Build/Products/Debug
-L/usr/local/cuda/lib -F/my_test_project/Build/Products/Debug
-filelist /my_test_project/Build/Intermediates/test.build/Debug/test.build/Objects-normal/x86_64/test.LinkFileList
-mmacosx-version-min=10.7
-lcudart
-lcuda
-o /my_test_project/Build/Products/Debug/test
ld:找不到文件:@rpath/CUDA.framework/Versions/A/CUDA for architecture x86_64 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
What's weird, is that when I go to the described path, I see the CUDA executable. The file is there!
奇怪的是,当我转到所描述的路径时,我看到了 CUDA 可执行文件。文件在那里!
When I use the cuComplex.h, which uses the library, every single mathematical expression (such as log, cos, sin, etc...) is an "undefined variable". However, the cuComplex.h library has inside it the library.
当我使用使用库的 cuComplex.h 时,每个数学表达式(例如 log、cos、sin 等)都是“未定义的变量”。但是,cuComplex.h 库内部包含该库。
The driver, the SDK and toolkit are well installed and everything works like a charm. I can get the SDK examples working. But I think I miss a detail to get the whole thing working.
驱动程序、SDK 和工具包都安装得很好,一切都像魅力一样。我可以让 SDK 示例正常工作。但我想我错过了让整个事情正常工作的细节。
回答by stoictopia
I have the same problem with CUDA 5.0 and Xcode 4.4.1 installed on Mountain Lion. The reason is that libcuda.dylib links CUDA.framework with rpath, which you can inspect with otool.
我在 Mountain Lion 上安装了 CUDA 5.0 和 Xcode 4.4.1 时遇到了同样的问题。原因是 libcuda.dylib 将 CUDA.framework 与 rpath 链接,您可以使用 otool 检查。
otool -L /usr/local/cuda/lib/libcuda.dylib
/usr/local/cuda/lib/libcuda.dylib:
/usr/local/cuda/lib/libcuda.dylib (compatibility version 1.1.0, current version 5.0.17)
@rpath/CUDA.framework/Versions/A/CUDA (compatibility version 1.1.0, current version 5.0.17)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.9.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
However, Xcode does not seem to recognize CUDA.framework under /Library/Frameworks. The reason is unknown. You have to add it yourself to your project.
但是,Xcode 似乎无法识别 /Library/Frameworks 下的 CUDA.framework。原因不明。您必须自己将其添加到您的项目中。
In your project property page, click Build Phases -> Link with Libraries. Select CUDA.framework. Add it using "Add Others" if it does not appear in the list. This way you get it linked.
在您的项目属性页面中,单击 Build Phases -> Link with Libraries。选择 CUDA.framework。如果它没有出现在列表中,请使用“添加其他”添加它。这样你就可以把它联系起来。
If you are writing Makefiles, you want to add this to fully automate the linking stage:
如果您正在编写 Makefile,您希望添加以下内容以完全自动化链接阶段:
-F/Library/Frameworks -framework CUDA
回答by Lev Kuznetsov
As an alternative that worked better for my setup is to change the path at libcuda like this:
作为对我的设置更有效的替代方法是像这样更改 libcuda 的路径:
sudo install_name_tool -change @rpath/CUDA.framework/Versions/A/CUDA \
/Library/Frameworks/CUDA.framework/CUDA \
/usr/local/cuda/lib/libcuda.dylib
As usual, don't paste a sudo command into your terminal if you don't understand what it does.
像往常一样,如果您不了解它的作用,请不要将 sudo 命令粘贴到您的终端中。
回答by d.b
I had the same problem compiling the CUDA 6.5 examples on OS X 10.10, with Xcode 6.1. The problem happened in the examples whose Makefiles contained the line:
我在使用 Xcode 6.1 在 OS X 10.10 上编译 CUDA 6.5 示例时遇到了同样的问题。问题发生在其 Makefiles 包含以下行的示例中:
ALL_LDFLAGS += -Xlinker -framework -Xlinker CUDA
The fix was to tell the linker about /Library/Frameworks, so that the above was replaced with 2 lines:
修复是告诉链接器有关 /Library/Frameworks 的信息,以便将上面的内容替换为 2 行:
ALL_LDFLAGS += -Xlinker -F/Library/Frameworks
ALL_LDFLAGS += -Xlinker -framework -Xlinker CUDA
Presumably your question is answered at this point, but this page is almost literally the only google result for "ld: framework not found CUDA" and hopefully this can save others some time.
大概你的问题在这一点上得到了回答,但这个页面几乎是“ld:framework not found CUDA”的唯一谷歌结果,希望这可以为其他人节省一些时间。
回答by Vijay
I had a similar CUDA linking issue with CUDA 8.0 and OSX 10.12 while compiling the sample files. Adding the following to the make files solved the problem.
在编译示例文件时,我在 CUDA 8.0 和 OSX 10.12 上遇到了类似的 CUDA 链接问题。将以下内容添加到 make 文件解决了问题。
LDFLAGS += -Xlinker -F/Library/Frameworks