autotools, build shared library, cuda


i wrote a library (*.cu) from which i’d like to build a dynamic library. I use autotools for that.

In the i added rules:

(NVCC) -o @ -c < (NVCCFLAGS)

(LIBTOOL) --tag=CC --mode=compile (NVCC) -o @ -c < $(NVCCFLAGS)

When building a dynamic library there is the problem that $(LIBTOOL) calls CC with the parameter -fPIC, which “nvcc” does not understand.

Can anybody give me a hint on how to proceed from here?

Is there a way to tell libtool to NOT use -fPIC ?

Thanks for any hints,

Hi everybody,

i can’t imagine that nobody else had the same problem, is there really no solution available?

Best regards,

Try this:

  1. Use nvcc to just compile the object
  2. keep using gcc to link

I have a project using automake where i use these rules:


%.o: %.h
(NVCC) (INCLUDES) -Xcompiler “-fPIC -DPIC” -c -o @ <

Since I had to pass different flags to my cuda files. I have explicit rules for each one of my cuda files.


nvcc --ptxas-options=-v -Xcompiler “-fPIC -DPIC” -arch $(ARCH) -O3 -c

nvcc --ptxas-options=-v --use_fast_math -arch $(ARCH) -O3 -Xcompiler “-fPIC -DPIC” -c

And remember to add the needed cudart library

libtest_la_LIBADD =
$(OTHER_LIBS) fileA.o fileB.o -L/usr/local/cuda/lib64 -lcudart -lstdc++