Compiling C code

I have a problem with compiling C code using the cuda runtime library. For example a simple source file

#include <stdio.h>

#include "cuda_runtime_api.h"

int main ( void )

{

	   cudaDeviceProp devProp;

	   cudaGetDeviceProperties(&devProp, 0);

	   return 0;

}

If I save this as main.cpp or main.cu it works fine when compiled by cl or g++.

If I save it as main.c it will not compile with either cl or gcc.

The errors I get say

‘cudaDeviceProp’ : undeclared identifier

I’ve tried including cuda_runtime.h and get the same result.

Up to now I’ve solved the problem by using .cpp main files but I need to add cuda code to an existing C program and it isn’t practical to rewrite the whole thing.

C++ has different linking conventions than C (function names get ‘mangled’ to reflect the types of their arguments), so any code that calls CUDA functions needs to be compiler as C++ code (nvcc automatically does this for files with the extension .cu).

What makes it impractical to compile the existing C program as C++? Very few C constructs aren’t valid C++.

The other option is to encapsulate all CUDA code into it’s own file. This is what I usually do. You just need to make sure that C header files included from .cpp or .cu files are encapsulated within [font=“Courier New”]extern “C”[/font] constructs like this:

extern "C" {

#include "mycode.h"

}

Hi Everyone!

I thought this topic may be suited for my question.

Im using win 7 x64, and VS 2008 prof, I have a solution where I have 3 static librarys: 2 regular c++, 1 cuda and a cuda project, which needs to use all of them.
My problem is the following: when i try to build the solution, all the librarys build just fine, but the cuda project does not, because it cannot find the files belonging to the librarys. I have dependencies set up, and also has the correct path-s set up in “additional include directorys” of the project.

Namely: fatal error C1083: Cannot open include file: ‘ga/std_stream.h’: No such file or directory While i have this in the “additional include directorys” e:\Diploma\MOGAlib\galib\ (galib folder does contain “ga” directory, which contains std_stream.h)

Also if i copy the “galib” folder into the project root everythings allright, at least thats what i did whit it the last time, but now I would like to get it straight, not just use some workarounds.
As i remember, this problem first occured, when I started to use the VS wizzard 2.3 instead of the 2.2, so maybe the problem is somewhere in the config changes, what happend between the two versions, but Im totally cluless about this one.

Another problem, since I started using win 7 setting up the path variable for cutil64D.dll does not work, I’ve done the same, which worked on vista, but now its still bitching about not finding the dll (again copying it to project root helps, but its not the best solution)

Oh and at last. Can anyone tell me what happend to CUDA SDK, I’ve only managed to find Cuda Toolkit 3 on Nvidia’s homepage, I thought ok, its melded with the sdk now, but it does not contain the dll-s which are needed to compile CUDA sources (or maybe I was blind, but it does not work) so I installed Cuda SDK 2.2 which I still had from the last time I worked with CUDA, that maybe also the source of some errors, i dont know.

Thanks in advance!
Exhodus

Hi Everyone!

I thought this topic may be suited for my question.

Im using win 7 x64, and VS 2008 prof, I have a solution where I have 3 static librarys: 2 regular c++, 1 cuda and a cuda project, which needs to use all of them.
My problem is the following: when i try to build the solution, all the librarys build just fine, but the cuda project does not, because it cannot find the files belonging to the librarys. I have dependencies set up, and also has the correct path-s set up in “additional include directorys” of the project.

Namely: fatal error C1083: Cannot open include file: ‘ga/std_stream.h’: No such file or directory While i have this in the “additional include directorys” e:\Diploma\MOGAlib\galib\ (galib folder does contain “ga” directory, which contains std_stream.h)

Also if i copy the “galib” folder into the project root everythings allright, at least thats what i did whit it the last time, but now I would like to get it straight, not just use some workarounds.
As i remember, this problem first occured, when I started to use the VS wizzard 2.3 instead of the 2.2, so maybe the problem is somewhere in the config changes, what happend between the two versions, but Im totally cluless about this one.

Another problem, since I started using win 7 setting up the path variable for cutil64D.dll does not work, I’ve done the same, which worked on vista, but now its still bitching about not finding the dll (again copying it to project root helps, but its not the best solution)

Oh and at last. Can anyone tell me what happend to CUDA SDK, I’ve only managed to find Cuda Toolkit 3 on Nvidia’s homepage, I thought ok, its melded with the sdk now, but it does not contain the dll-s which are needed to compile CUDA sources (or maybe I was blind, but it does not work) so I installed Cuda SDK 2.2 which I still had from the last time I worked with CUDA, that maybe also the source of some errors, i dont know.

Thanks in advance!
Exhodus

Hi Everyone!

I thought this topic may be suited for my question.

Im using win 7 x64, and VS 2008 prof, I have a solution where I have 3 static librarys: 2 regular c++, 1 cuda and a cuda project, which needs to use all of them.
My problem is the following: when i try to build the solution, all the librarys build just fine, but the cuda project does not, because it cannot find the files belonging to the librarys. I have dependencies set up, and also has the correct path-s set up in “additional include directorys” of the project.

Namely: fatal error C1083: Cannot open include file: ‘ga/std_stream.h’: No such file or directory While i have this in the “additional include directorys” e:\Diploma\MOGAlib\galib\ (galib folder does contain “ga” directory, which contains std_stream.h)

Also if i copy the “galib” folder into the project root everythings allright, at least thats what i did whit it the last time, but now I would like to get it straight, not just use some workarounds.
As i remember, this problem first occured, when I started to use the VS wizzard 2.3 instead of the 2.2, so maybe the problem is somewhere in the config changes, what happend between the two versions, but Im totally cluless about this one.

Another problem, since I started using win 7 setting up the path variable for cutil64D.dll does not work, I’ve done the same, which worked on vista, but now its still bitching about not finding the dll (again copying it to project root helps, but its not the best solution)

Oh and at last. Can anyone tell me what happend to CUDA SDK, I’ve only managed to find Cuda Toolkit 3 on Nvidia’s homepage, I thought ok, its melded with the sdk now, but it does not contain the dll-s which are needed to compile CUDA sources (or maybe I was blind, but it does not work) so I installed Cuda SDK 2.2 which I still had from the last time I worked with CUDA, that maybe also the source of some errors, i dont know.

Thanks in advance!
Exhodus

Hi Everyone!

I thought this topic may be suited for my question.

Im using win 7 x64, and VS 2008 prof, I have a solution where I have 3 static librarys: 2 regular c++, 1 cuda and a cuda project, which needs to use all of them.
My problem is the following: when i try to build the solution, all the librarys build just fine, but the cuda project does not, because it cannot find the files belonging to the librarys. I have dependencies set up, and also has the correct path-s set up in “additional include directorys” of the project.

Namely: fatal error C1083: Cannot open include file: ‘ga/std_stream.h’: No such file or directory While i have this in the “additional include directorys” e:\Diploma\MOGAlib\galib\ (galib folder does contain “ga” directory, which contains std_stream.h)

Also if i copy the “galib” folder into the project root everythings allright, at least thats what i did whit it the last time, but now I would like to get it straight, not just use some workarounds.
As i remember, this problem first occured, when I started to use the VS wizzard 2.3 instead of the 2.2, so maybe the problem is somewhere in the config changes, what happend between the two versions, but Im totally cluless about this one.

Another problem, since I started using win 7 setting up the path variable for cutil64D.dll does not work, I’ve done the same, which worked on vista, but now its still bitching about not finding the dll (again copying it to project root helps, but its not the best solution)

Oh and at last. Can anyone tell me what happend to CUDA SDK, I’ve only managed to find Cuda Toolkit 3 on Nvidia’s homepage, I thought ok, its melded with the sdk now, but it does not contain the dll-s which are needed to compile CUDA sources (or maybe I was blind, but it does not work) so I installed Cuda SDK 2.2 which I still had from the last time I worked with CUDA, that maybe also the source of some errors, i dont know.

Thanks in advance!
Exhodus