undefined reference to `cudaMalloc' error Please help

Hello,

I am using Matlab R2008a in Ubuntu 8.10 and I get the following error when I try to make.

[b]$ make -lcudart
/usr/local/matlab/bin/mex CFLAGS=’-fPIC -D_GNU_SOURCE -pthread -fexceptions’ COPTIMFLAGS=’-O3 -funroll-loops -msse2’ fft2_cuda.c
-I/usr/local/cuda/include -L/usr/local/cuda/lib -lcufft -Wl,-rpath,/usr/local/cuda/lib
fft2_cuda.o: In function mexFunction': fft2_cuda.c:(.text+0x8d8): undefined reference to cudaMalloc’
fft2_cuda.c:(.text+0x8f6): undefined reference to cudaMemcpy' fft2_cuda.c:(.text+0x95e): undefined reference to cudaMemcpy’
fft2_cuda.c:(.text+0x9c4): undefined reference to `cudaFree’
collect2: ld returned 1 exit status

mex: link of ' "fft2_cuda.mexglx"' failed.

make: *** [fft2_cuda.mexglx] Error 1
[/b]

I read that this is because the CUDA runtime library is missing and was advised to include -lcudart but I still seems to be getting the error.

Any help is greatly appreciated.

Thank you.

Here is the relevant section from my makefile:

[codebox]SDK_HOME = /home/$(USER)/NVIDIA_CUDA_SDK

INCLUDEDIR = -I$(CUDAHOME)/include -I$(SDK_HOME)/common/inc

INCLUDELIB = -L$(CUDAHOME)/lib -lcufft -lcudart -Wl,-rpath,$(CUDAHOME)/lib

[/codebox]

You need to install the SDK in your home directory and run make in the top-level dir before it will work.

Thanks a lot Riedijk.

It helped a bit. My makefile didn’t have the SDK_HOME path. Strange.

So I have my NVIDIA_CUDA_SDK in my /home directory and the Matlab_Cuda directory also in the /home directory.

Now I get this error:

[b]1$ make

/usr/local/matlab/bin/mex CFLAGS=’-fPIC -D_GNU_SOURCE -pthread -fexceptions’ COPTIMFLAGS=’-O3 -funroll-loops -msse2’ fft2_cuda.c \

    -I/usr/local/cuda/include -I(SDK_HOME)/common/inc -L/usr/local/cuda/lib -lcufft -lcudart -Wl,-rpath,/usr/local/cuda/lib

/bin/sh: Syntax error: “(” unexpected

make: *** [fft2_cuda.mexglx] Error 2

[/b]

No idea how to figure this out.

Do I need to have the Matlab_Cuda directory somewhere else?

Thanks a lot mate.

-I(SDK_HOME)/common/inc

The variable does not get pasted here, did you loose the last in INCLUDEDIR = -I(CUDAHOME)/include -I$(SDK_HOME)/common/inc ?

man you are a genius!

yes… I was missing the $.

It compiled fine. Now I Have to get back and see if the rest works…!

Thanks a million mate!!!

Hi! I am getting the same error while trying to install MATLAB plug-in for CUDA - the error message is

/usr/local/bin/mex CFLAGS=’-fPIC -D_GNU_SOURCE -pthread -fexceptions’ COPTIMFLAGS=’-O3 -funroll-loops -msse2’ fft2_cuda.c
-I/usr/local/cuda/include -I/home/fguichard/NVIDIA_CUDA_SDK/common/inc -L/usr/local/cuda/lib -lcufft -Wl,-rpath,/usr/local/cuda/lib

Warning: You are using gcc version “4.3.3-5ubuntu4)”. The earliest gcc version supported
with mex is “4.1”. The latest version tested for use with mex is “4.2”.
To download a different version of gcc, visit http://gcc.gnu.org

fft2_cuda.o: In function mexFunction': fft2_cuda.c:(.text+0xe4f): undefined reference to cudaMalloc’
fft2_cuda.c:(.text+0xe64): undefined reference to cudaMemcpy' fft2_cuda.c:(.text+0xeac): undefined reference to cudaMemcpy’
fft2_cuda.c:(.text+0xf01): undefined reference to `cudaFree’
collect2: ld returned 1 exit status

mex: link of ' "fft2_cuda.mexa64"' failed.

make: *** [fft2_cuda.mexa64] Error 1

I added the $SDK_HOME variable to the Makefile as suggested, but it didn’t change anything… any help would be really appreciated! Can someone post an example Makefile?

Thanks

Hi, I am facing the same problems as icypoe. Compiling CUDA projects in C works fine. But however Matlab has problems to find these cuda functions. Anyone got a solution?

Thanks

Never tried building kernels for Matlab, but I am guessing that linking with -lcudart will fix those problems.