Building a shared library with dependencies on CUDA Driver API


I’m trying to build a shared library for use with the Python “ctypes” foreign function interface package. I’m working on a 64-bit Linux system (Ubuntu 10.04) with CUDA Toolkit 2.3. The particular shared library I’m trying to build is for MAGMA (Matrix Algebra on GPU and Multicore Architectures). I’m starting with shared libraries that were posted on the MAGMA User Forum ( and, and am also compiling a source code file “get_nb.cpp” based on posts by other users on the MAGMA User Forum. The ctypes LoadLibrary function does not allow one to specify additional libraries, so it must be able to resolve all symbols in the single shared library name it is passed. Here is my current best attempt to create a single shared library ( with all of the necessary functions:

gcc -shared get_nb.o -o -lstdc++ -L/home/cmejia/Documents/magma_0.2/lib -lmagma -lmagmablas /usr/lib64/ -L/usr/local/cuda/lib64 -lcublas -lcudart

However, when I execute the Python ctypes command LoadLibrary(‘’) I get the following error:

OSError: /usr/local/magma_0.2/lib/ undefined symbol: cuDeviceTotalMem

Previously, I had been able to eliminate these “undefined symbol” errors by adding the appropriate libraries to the gcc command line. However, there is no library (that I am aware of) for the CUDA Driver API. I tried replacing “gcc” with “nvcc” in my command line above, but still received the same error from the Python ctypes LoadLibrary command. Does anyone have ideas on how I should proceed? FYI, I am posting my issue in this Forum rather than the MAGMA User Forum because I believe that I have worked past any issues with the MAGMA libraries, and am now need help with nvcc and the CUDA Driver API.

Thanks in advance,

The driver api library is - it ships with the driver package and should be in /usr/lib


I appended -lcuda to my gcc command line, and it fixed the undefined symbol error. That was easy!

Thanks again,