gcc:language c++ not recognized nvcc compile error

Hi Guys,

I tried to compile a simple cuda code on my mac (version 10.5.8):

  1 #include <stdio.h>      
  2 
  3 __global__ void foo()
  4 {      5 }
  6 
  7 int main()
  8 {
  9   foo<<<1,1>>>();
 10   printf("CUDA error: %s\n", cudaGetErrorString(cudaGetLastE
 10 rror()));  
 11   return 0;
 12 }

$ nvcc test.cu
gcc: language c++ not recognized
gcc: language c++ not recognized
gcc: test.cu: linker input file unused because linking not done
Catastrophic error: cannot open source file “/tmp/tmpxft_00005c75_00000000-4_test.cpp1.ii”

1 catastrophic error detected in the compilation of “/tmp/tmpxft_00005c75_00000000-4_test.cpp1.ii”.
Compilation terminated.

I do have nvcc and gcc installed.
$ nvcc -V
nvcc: NVIDIA ® Cuda compiler driver
Copyright © 2005-2010 NVIDIA Corporation
Built on Thu_Jun_17_16:11:55_PDT_2010
Cuda compilation tools, release 3.1, V0.2.1221

$ gcc -v
Using built-in specs.
Target: i386-apple-darwin9.7.0
Configured with: /eng/upc/bld/upc-4.3.2.4/src/configure --prefix=/usr/local/upc --enable-languages=c,upc --disable-upc-link-script --without-gnu-ld --with-gmp=/opt/local --with-mfpr=/opt/local
Thread model: posix
gcc version 4.3.2 20090617 (dev) (GCC UPC 4.3.2-4) (GCC)

Any suggestion is appreciated.

Hello Benetion,

That’s weird. Did you install GCC by yourself or are you using the one that comes when you install Xcode?

Also, have you tried compiling non-CUDA C++ programs using g++?

Alejandro.-

Hello Benetion,

That’s weird. Did you install GCC by yourself or are you using the one that comes when you install Xcode?

Also, have you tried compiling non-CUDA C++ programs using g++?

Alejandro.-

Hi Alejandro,

This is not the one with xcode. Yes, g++ works fine.

After changing back to xcode gcc, nvcc seems fine now. Thanks!

Hi Alejandro,

This is not the one with xcode. Yes, g++ works fine.

After changing back to xcode gcc, nvcc seems fine now. Thanks!

You’ve got a custom-build gcc version where C++ support has been switched off. However, CUDA uses C++ mode to implement its language extensions, even if you select C as language. As you figured out, switching to the gcc supplied with Xcode solves the problem, as would a custom gcc install with C++ enabled.

You’ve got a custom-build gcc version where C++ support has been switched off. However, CUDA uses C++ mode to implement its language extensions, even if you select C as language. As you figured out, switching to the gcc supplied with Xcode solves the problem, as would a custom gcc install with C++ enabled.

Thanks for the comments.

Thanks for the comments.