2
votes

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.

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 :

Compiler for C/C++/Objective-C : LLVM GCC 4.2

Other Linker Flag : -lcuda, -lcudart

Header Search Path : /usr/local/cuda/include

Library Search Path : /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)

What's weird, is that when I go to the described path, I see the CUDA executable. The file is there!

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.

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.

4
Hello Pierre-Luc, welcome to Stack Overflow. When you create your CUDA project, do you create it for the same architecture (32-bit / 64-bit), as the one for which you installed CUDA? - Roger Dahl
Hi ! Thank you for your answer ! Yes, absolutely. I've installed CUDA in x64. Even if I set the property "Architecture" to 32-bit and "Valid Architecture" to i386, the same thing appears but says " ld: file not found: @rpath/CUDA.framework/Versions/A/CUDA for architecture i386" - Pierre-Luc Delisle
I've even tried it to compile in terminal. I get the exact same errors. - Pierre-Luc Delisle
Just for kicks, have you tried building a release version? - Roger Dahl
Maybe an issue with permissions? Maybe try compiling as root. - Roger Dahl

4 Answers

6
votes

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.

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.

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.

If you are writing Makefiles, you want to add this to fully automate the linking stage:

-F/Library/Frameworks -framework CUDA
0
votes

As an alternative that worked better for my setup is to change the path at libcuda like this:

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.

0
votes

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:

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:

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.

0
votes

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.

LDFLAGS += -Xlinker -F/Library/Frameworks