CUDA SHARED OBJECT HELP Creating a CUDA .so file

Ive been trying to generate a cuda shared object of a modified (but working) sobelfilter using the makefile provided in the SDK, not getting anywhere.

According to other threads, my makefile should look like this:

# Add source files here

EXECUTABLE      := mySobeldll

# Cuda source files (compiled with cudacc)

CUFILES         := mySobeldllComb.cu

# C/C++ source files (compiled with gcc / c++)

CCFILES         := 

CU_DEPS         := 

##################################

# Rules and targets

include ../../common/common.mk

NVCCFLAGS += -Xcompiler -fPIC

CFLAGS += -fPIC

CXXFLAGS += -fPIC

LINK += -shared

I’ve tried many other things, but thats the makefile with every compiler’s flags set.

I usually get the error:

Can some one please tell me what i’m doing wrong?

Thanks in advance!

As I can remember, you should use “-Xcompiler -fPIC” in your nvcc flags

Thanks for the quick response, but haven’t i done that in the makefile i posted?

NVCCFLAGS += -Xcompiler -fpic

Am i doing something wrong or missing something?

I’m on a 64 bit system - if that helps.

Here I had that problem on a 64-bit machine as well (in 32-bit you don’t need the -fPIC). and In my case it went away after recompiling all object files with that flag. Weird.

I changed my .cu file a bit and now this is what I’m getting:

/usr/bin/ld: ../../lib/libcutil.a(cutil.cpp_o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC

../../lib/libcutil.a: could not read symbols: Bad value

collect2: ld returned 1 exit status

make: *** [../../bin/linux/release/mySobeldll.so] Error 1

Any suggestions?

You probably need to recompile libcutil.a using the -fPIC option. If you change

Compilers

NVCC := nvcc

CXX := g++

CC := gcc

LINK := g++ -fPIC

to

Compilers

NVCC := nvcc -Xcompiler -fPIC

CXX := g++ -fPIC

CC := gcc -fPIC

LINK := g++ -fPIC

in sdk/common/common.mk and recompile libcutil, it might work better. I had a similar problem with cudpp and doing this solved it.

/Lars