Reputation: 41
I have been searching everywhere for a solution to my problem: I cannot run a .cpp file using CUDA. I think this is a module error since I get the following error:
g++ -L/usr/local/cuda/lib64 -L~/NVIDIA_GPU_Computing_SDK/shared/lib/linux -L~/NVIDIA_GPU_Computing_SDK/C/common/lib/linux -L~/NVIDIA_GPU_Computing_SDK/C/lib -lcutil -lcudpp -lcuda -lcudart -lcurand -o my_file my_file.o
/usr/bin/ld: cannot find -lcutil
/usr/bin/ld: cannot find -lcudpp
My makefile looks like this:
EXECUTABLE := my_file
SDKPATH := ~/NVIDIA_GPU_Computing_SDK
CUDAPATH := /usr/local/cuda
LDFLAGS := -L$(CUDAPATH)/lib64 -L$(SDKPATH)/shared/lib/linux -L$(SDKPATH)/C/common/lib/linux -L$(SDKPATH)/C/lib -lcutil -lcudpp -lcuda -lcudart -lcurand
CXFLAGS := -I$(CUDAPATH)/include -I$(SDKPATH)/shared/inc -I$(SDKPATH)/C/common/inc
CXX := g++
NVCC := $(CUDAPATH)/bin/nvcc
$(EXECUTABLE): my_file.o
$(CXX) $(LDFLAGS) -o $(EXECUTABLE) my_file.o
my_file.o: my_file.cu
$(NVCC) $(CXFLAGS) -c my_file.cu
When I, instead try to run the file manually I get the following output:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
my_file.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00000e8f_00000000-1_my_file.cudafe1.cpp:(.text+0xf): undefined reference to `__cudaUnregisterFatBinary'
my_file.o: In function `__sti____cudaRegisterAll_59_tmpxft_00000e8f_00000000_4_my_file_cpp1_ii_71dc03a4()':
tmpxft_00000e8f_00000000-1_my_file.cudafe1.cpp:(.text+0x1f): undefined reference to `__cudaRegisterFatBinary'
collect2: ld returned 1 exit status
I'm a total noob when it comes to linux. Can anyone please shed some light on this situation.
Regards
Upvotes: 4
Views: 1109
Reputation: 72350
You have an ordering problem in the linking phase of your build. Because the libraries you specify are provided before the files that require them, they get discarded. If you change your makefile to something like:
LDFLAGS := -L$(CUDAPATH)/lib64 -L$(SDKPATH)/shared/lib/linux -L$(SDKPATH)/C/common/lib/linux
LIBS := -lcutil -lcudpp -lcuda -lcudart -lcurand
....
$(EXECUTABLE): my_file.o
$(CXX) $(LDFLAGS) -o $(EXECUTABLE) my_file.o $(LIBS)
you should find the problem goes away.
Upvotes: 4