VC++ 2008 e CUDA (NVIDIA)|VC++ 2008 and CUDA (NVIDIA)

Let me guess: you just wrote your new, shining CUDA application to unleash all the horsepower of your GPU and you are getting some compilation errors in Visual Studio. Some really weird errors. Something like:

1>CUDA_myfile.cu_generated.c
1>C:\Programmi\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h(52) : error C2059: syntax error : ‘string’
1>C:\Programmi\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h(61) : error C2059: syntax error : ‘string’
1>c:\cuda\include\vector_types.h(426) : error C2059: syntax error : ‘type’
1>c:\cuda\include\vector_types.h(427) : error C2059: syntax error : ‘type’
1>c:\cuda\include\vector_types.h(428) : error C2054: expected ‘(‘ to follow ‘operator’
1>c:\cuda\include\vector_types.h(428) : error C2059: syntax error : ‘type’
1>c:\cuda\include\vector_types.h(430) : error C2059: syntax error : ‘}’
1>C:\CUDA\bin/../include\cuda_runtime_api.h(79) : error C2059: syntax error : ‘string’
1>C:\Programmi\Microsoft Visual Studio 9.0\VC\INCLUDE\crtdefs.h(485) : error C2059: syntax error : ‘string’

Right? This is your lucky day. After some struggling, I figured out the solution to this weird issue! Simply right click on the file in the “Solution Explorer” then selectd “Properties”. Now choose “Compile as C++ Code (/TP)” in “Configuration Properties->C/C++->Advanced->Compile As” and apply the changes. Compile your project and.. it should work.

Lasciatemi indovinare: avete appena scritto la vostra nuova, fiammante, applicazione CUDA per scatenare tutta la potenza della vostra GPU e vi ritrovate alcuni strani errori in Visual Studio durante la compilazione. Errori tipo:

1>CUDA_myfile.cu_generated.c
1>C:\Programmi\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h(52) : error C2059: syntax error : ‘string’
1>C:\Programmi\Microsoft Visual Studio 9.0\VC\INCLUDE\vadefs.h(61) : error C2059: syntax error : ‘string’
1>c:\cuda\include\vector_types.h(426) : error C2059: syntax error : ‘type’
1>c:\cuda\include\vector_types.h(427) : error C2059: syntax error : ‘type’
1>c:\cuda\include\vector_types.h(428) : error C2054: expected ‘(‘ to follow ‘operator’
1>c:\cuda\include\vector_types.h(428) : error C2059: syntax error : ‘type’
1>c:\cuda\include\vector_types.h(430) : error C2059: syntax error : ‘}’
1>C:\CUDA\bin/../include\cuda_runtime_api.h(79) : error C2059: syntax error : ‘string’
1>C:\Programmi\Microsoft Visual Studio 9.0\VC\INCLUDE\crtdefs.h(485) : error C2059: syntax error : ‘string’

Giusto? Oggi è il vostro giorno fortunato. Dopo un pò di delirio, ho trovato la soluzione a questo insolito problema! Fate semplicemente click di destro sul file nel “Solution Explorer” e scegliete “Proprietà”. Ora impostate “Compile as C++ Code (/TP)” in “Configuration Properties->C/C++->Advanced->Compile As”e salvate le modifiche. Provate a compilare e.. dovrebbe andare!