-fPIC in CUDA SDK missing -fPIC option in CUDA SDK's common.mk

As pointed out by some source compiling position independent code with the -fPIC flag is mandatory when compiled shared libraries for AMD64 architecture.

In the CUDA SDK’s “common/common.mk” file included from the Makefiles, “-fPIC” is specified only for the linker, not for the C and C++ compiler :

whereas, it should be :

This poses problem when trying to compile shared libraries, and as of CUDA version 2.1, still yields the following error message :

Could NVIDIA’s developer please fix ?

Thank you very much !

1 Like

Has anyone touched this problem?

I’m getting the issue, as well. There are posts on the forum here about adding it ourselves, but then you need to recompile the libcutil.a. I’ve included the -fPIC option in my common.mk, but having when trying to recompile, I’m getting the following error:

target: /opt/cuda_sdk/lib/libcutil.a
linkline: ar rucv /opt/cuda_sdk/lib/libcutil.a obj/release/bank_checker.cpp.o obj/release/cmd_arg_reader.cpp.o obj/release/cutil.cpp.o obj/release/stopwatch.cpp.o obj/release/stopwatch_linux.cpp.o obj/release/multithreading.cpp.o
targetdir: /opt/cuda_sdk/lib
/opt/cuda_sdk/lib/libcutil.a
make: /opt/cuda_sdk/lib/libcutil.a: Command not found
make: *** [all] Error 127

Has anyone else seen this??

You have a broken makefile somehow. What you are seeing is nothing to do with whether objects contain position independent code. On the subject of libctuil itself, it is worth pointing out that it is not intended for use in anything outside of the SDK examples (which I guess is mostly why it is just shipped as a static library in the SDK rather than in the actual toolkit), and you really shouldn’t need to (or just plain shouldn’t) use it in your own code.