--host-compilation not obeyed nvcc compiling source as C++ when I want it to compile C

I cannot get nvcc to invoke gcc as a C compiler

On Linux, nvcc (the CUDA compiler) invokes gcc to actually do the compilation.

In the example, here, I need to pass -std=c99 to gcc. This flag can only be used with gcc to compile C code.

nvcc --host-compilation c --compiler-options “-std=c99” -I. -I… -c RT_CUDA_AdaptiveTimescale.cu
cc1plus: warning: command line option “-std=c99” is valid for C/ObjC but not for C++

cc1plus is the gcc C++ compiler engine (might not be the precise term). cc1 would be the gcc C compiler engine.

The --host-compilation c should override the default behaviour of nvcc to invoke the C++ compiler so that gcc is invoked as a C compiler.

A little extra info is provided by using the --dryrun option.

nvcc --dryrun --host-compilation c --compiler-options “-std=c99” -I. -I… -c RT_CUDA_AdaptiveTimescale.cu
# _SPACE_= # MODE=DEVICE
# _HERE_=/usr/local/cuda/bin # THERE=/usr/local/cuda/bin
# TOP=/usr/local/cuda/bin/.. # LD_LIBRARY_PATH=/usr/local/cuda/bin/…/lib:/usr/local/cuda/bin/…/extools/lib:/lib:/usr/lib:/usr/local/lib:/usr/X11R6/lib:/usr/local/cuda/lib
# PATH=/usr/local/cuda/bin/../open64/bin:/usr/local/cuda/bin/../bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/local/cuda/bin # INCLUDES="-I/usr/local/cuda/bin/…/include" “-I/usr/local/cuda/bin/…/include/cudart”
# LIBRARIES= "-L/usr/local/cuda/bin/../lib" -lcudart # CUDAFE_FLAGS=
# OPENCC_FLAGS= # PTXAS_FLAGS=
# gcc -D__CUDA_ARCH__=100 -E -x c++ -DCUDA_NO_SM_12_ATOMIC_INTRINSICS -DCUDA_NO_SM_13_DOUBLE_INTRINSICS -DCUDA_FLOAT_MATH_FUNCTIONS -DCUDA_NO_SM_11_ATOMIC_INTRINSICS "-I/usr/local/cuda/bin/../include" "-I/usr/local/cuda/bin/../include/cudart" -I. -D__CUDACC__ -C -std=c99 -I"." -I".." -include "cuda_runtime.h" -m64 -o "/tmp/tmpxft_0000053e_00000000-4_RT_CUDA_AdaptiveTimescale.cpp1.ii" "RT_CUDA_AdaptiveTimescale.cu" # cudafe --m64 --gnu_version=40303 --diag_error=host_device_limited_call --diag_error=ms_asm_decl_not_allowed --type_traits_helpers -tused --no_rtti --no_exceptions --gen_c_file_name “/tmp/tmpxft_0000053e_00000000-1_RT_CUDA_AdaptiveTimescale.cudafe1.c” --stub_file_name “/tmp/tmpxft_0000053e_00000000-1_RT_CUDA_AdaptiveTimescale.cudafe1.stub.c” --stub_header_file_name “/tmp/tmpxft_0000053e_00000000-1_RT_CUDA_AdaptiveTimescale.cudafe1.stub.h” --gen_device_file_name “/tmp/tmpxft_0000053e_00000000-1_RT_CUDA_AdaptiveTimescale.cudafe1.gpu” --include_file_name “/tmp/tmpxft_0000053e_00000000-3_RT_CUDA_AdaptiveTimescale.fatbin.c” “/tmp/tmpxft_0000053e_00000000-4_RT_CUDA_AdaptiveTimescale.cpp1.ii”
#$ gcc -D__CUDA_ARCH__=100 -E -x c -DCUDA_NO_SM_12_ATOMIC_INTRINSICS -DCUDA_NO_SM_13_DOUBLE_INTRINSICS -DCUDA_FLOAT_MATH_FUNCTIONS -DCUDA_NO_SM_11_ATOMIC_INTRINSICS “-I/usr/local/cuda/bin/…/include” “-I/usr/local/cuda/bin/…/include/cudart” -I. -D__CUDACC__ -C -std=c99 -I"." -I"…" -m64 -o “/tmp/tmpxft_0000053e_00000000-5_RT_CUDA_AdaptiveTimescale.cpp2.i” “/tmp/tmpxft_0000053e_00000000-1_RT_CUDA_AdaptiveTimescale.cudafe1.gpu”
(more output follows)

In the first call to gcc, the flag “-x c++” is added, invoking gcc as a C++ compiler.
Then cudafe is invoked followed by a second invocation of gcc but this time with “-x c” which invokes gcc as a C compiler.

I won’t show it here, but invoking nvcc without “–host-compilation c” or even using it as “–host-compilation c++” doesn’t change the --dryrun output.

BTW, I’ve also tried --host-compilation=c, --host-compilation C and --host-compilation=C. No difference

Details about nvcc:

nvcc --version
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2009 NVIDIA Corporation
Built on Thu_Apr__9_05:05:52_PDT_2009
Cuda compilation tools, release 2.2, V0.2.1221

Though I had the same problem with release 2.1.

The OS is Debian:
Linux 2.6.26-2-amd64 #1 SMP Fri Mar 27 04:02:59 UTC 2009 x86_64 GNU/Linux

If anyone can shed some light on this problem, I would very much appreciate it.

Cheers,
Eric

–host-compilation won’t actually compile as C, it will compile as C++ with some things turned off (exceptions, for one).

Hmmm… OK. Thanks for the reply. I’ll need to find a workaround.

Cheers,

Eric

I’m having the exact same problem, I need to compile in C99
does anyone know a workaround ?

By the way, the option --host-compilation is deprecated according to the compiler yet it still appears in the document “CUDA compiler driver NVCC”.

Please see this thread:
http://forums.nvidia.com/index.php?showtopic=217079&st=0&p=1340190&hl=memstick&fromsearch=1&#entry1340190