simple question on CUBLAS cublasInit

Hi guys,

When compiling the following code:

#include <cublas.h>


cublasStatus status;

status = cublasInit();

I get

Undefined reference to `cublasInit’…

Any ideas why?


you need to link with cublas.lib which loates in C:\CUDA\lib64 or in /usr/local/cuda/lib


Thanks. If someone else has the same problem, what I did was to add to the Makefile:

# Additional libraries needed by the project


and now it compiles ok

Hi there! Got the same problem. Which makefile did you edit? My CUDA-Program does not have a makefile, but I think i set the LD_LIBRARY_PATH correctly in my .bashrc:


The .so files are all there :)

My program is not that big (just starting to make myself comfortable with cuBLAS):

#include <vector>

#include <cublas.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

using namespace std;

vector<int> cVector;

int main(int argc, const char* argv[]) {

	cublasStatus status;

	status = cublasInit();

		if (status != CUBLAS_STATUS_SUCCESS) {

			fprintf (stderr, "!!!! CUBLAS initialization error\n");

			return EXIT_FAILURE;




and i get the following error:

/tmp/tmpxft_00000d92_00000000-1_01_vector.o: In function `main': undefined reference to `cublasInit'

collect2: ld returned 1 exit status

Does anybody have a solution? I’m using CUDA 2.3.

LD_LIBRARY_PATH doesn’t effect compilation behaviour. You need to explicitly specify you want to link CUBLAS, something like this:

cc -o mycode mycode.c -lcublas -lcudart

and you should be in business,…

Great! Thanks!

nvcc -lcublas

did the job!

Hello all.

I have the same problem when I compile the simpleCuda example under Linux CentOS 5.2 Cuda 3.0 version.

I use this commands to compile the example:

nvcc ./simpleCUBLAS.c -o simpleCUBLAS -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudartemu -lcublasemu -deviceemu


nvcc ./simpleCUBLAS.c -o simpleCUBLAS -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudartemu -lcublasemu

All dependenses are correct => /usr/local/cuda/lib64/ (0x00002ab850e86000) => /usr/local/cuda/lib64/ (0x00002ab8510c1000)

But still it gives

simpleCUBLAS test running..

!!!! CUBLAS initialization error

No you don’t.

You are not compiling for device emulation, but are linking with the device emulation libraries. That will not work.

Thanks for reply.

I`ve tried to compile the example with cublasemu library.

I use such command:

nvcc ./simpleCUBLAS.c -o simpleCUBLAS -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudart -lcublasemu -lcuda

But the program says:

“Segmentation fault”

Let me try again. If you are trying to use device emulation, the you need to tell nvcc using the -deviceemu flag, otherwise it won’t work. If you are trying to compile for a device, don’t use the device emulation libraries. Do one or the other, but don’t mix the two because, as you have found out, it doesn’t work.

I pretty understand what emulation mode does. When I tried to compile it for a device with the help of this command:

nvcc ./simpleCUBLAS.c -o simpleCUBLAS -I/usr/local/cuda/include -L/usr/local/cuda/lib64 -lcudart -lcublas

it still says:

simpleCUBLAS test running..

!!!! CUBLAS initialization error

And you have a working, cuda compatible video card?

Thanks for reply. There is something strang with my video card.

What card, driver and CUDA version are you using?

I use NVIDIA Geforce GTX 280, Cuda version 2.3, driver version is 190.18.

I`ve reinstalled all software and it started working in emulation mode, but when I try to run it as for device it says, that there is no device found. Probably I must install the latest software and configure nvidia card correctly. Because I have to cards connected to one PC(nVidia and AMD).

P.S. I`ve noticed another problem. When I start the my program compiled for cuda in emulation mode on my laptop(Acer 5632 WLMI) the function cudaGetDeviceCount returns 0. But when I start the same example on PC in emulation mode all is working ok. :(