bug building shared library shared library that worked with the 0.81

I wanted to update my framework from the 0.81 to the 1.0 version.

But I realized that the code is not compatible with the new release.

So I tried to fix the problems but I’m still stuck with this :

Basically I want to create a .so shared library in order to interact with some python code.

let me give you the simplest example :

file1: libMyCuda.cu

#include <stdio.h>

#include <cutil.h>

extern "C" void mytest()


  printf("simple inC\n");


here is how I compile it :

nvcc -o libMyCuda.o -shared -c libMyCuda.cu -Xcompiler “-m32” -Xcompiler " " (includes) (libs)

g++ -shared -fPIC -o libMyCuda.so libMyCuda.o (includes) (libs)

now I have my shared library I tried to use it in c :

file2: reader.c

#include <stdio.h>

extern void mytest();




  return 0;


here is how I compile it :

gcc -o reader reader.c -L. -lMyCuda -lm

this works fine.

now my python file :

import ctypes

mylib = ctypes.cdll.LoadLibrary("./inC/libThorCuda.so")


print 'worked'

here is what I get :

simple inC


*** glibc detected *** python: double free or corruption (fasttop): 0x081c7030 ***

I tried to use valgrind to understand what was going on.

here is an example of errors:

==32638== Invalid free() / delete / delete[]

==32638==    at 0x4020CC7: operator delete(void*) (vg_replace_malloc.c:244)

==32638==    by 0x459181F: __cudaUnregisterFatBinary (in /usr/local/cuda/lib/libcudart.so.1.0)

==32638==    by 0x43CC015: __cudaUnregisterBinaryUtil (in /home/projects/sandbox/lib1.0/inC/libMyCuda.so)

==32638==    by 0x43CC022: __cudaUnregisterBinary (in /home/projects/sandbox/lib1.0/inC/libMyCuda.so)

I have no idea of what the hack it’s going on, what is cudaUnregisterFatBinary and cudaUnregisterBinary suppose to do ?

I think there is a double free somewhere, but where ?

I’d love to move to this new version, so I’m asking for help here !