cudaDeviceProp undeclared (first use in this function)

hi, i have some problems when i try compile a program that uses this function.

i have a .cu file where i have one function that use the function and another file .c where i call the .cu function.

nvcc -o projecto.o -c -arch=sm_11 -O3 -I. projecto.cu
gcc main.c `pkg-config libglade-2.0 gtk+-2.0 --cflags` `pkg-config libglade-2.0 gtk+-2.0 --libs` -Wl,-export-dynamic projecto.o -I/usr/local/cuda/include -I/home/pinto/NVIDIA_CUDA_SDK/common/inc -L/usr/local/cuda/lib -L/home/pinto/NVIDIA_CUDA_SDK/lib -L/home/pinto/NVIDIA_CUDA_SDK/common/lib -lcuda -lcudart -lcutil -lm -lmpich

ERROR:

projecto.cu: In function âgpu_infoâ:

projecto.cu:44: error: âcudaDevicePropâ undeclared (first use in this function)

projecto.cu:44: error: (Each undeclared identifier is reported only once

projecto.cu:44: error: for each function it appears in.)

projecto.cu:44: error: expected â;â before âdevicePropâ

LINE 44:

cudaDeviceProp deviceProp;

Did you include the correct headers?

#include <cuda.h>
#include <cuda_runtime_api.h>

N.

yes, i include in both

projecto.cu

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <cuda.h>

#include <cuda_runtime_api.h>

main.c

#include <gtk/gtk.h>

#include <glade/glade.h>

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

#include <time.h>

#include <math.h>

#include <cuda.h>

#include <cuda_runtime_api.h>

#include "projecto.cu"

Take a look at the deviceQuery project in the SDK and see what you’re doing differently…

N.

Hi, i up this topic because i have the same problem,

how can i resolve it?

try including builtin_types.h

That will get you all the types that the runtime library uses.

I tried this without any result.

Buf i found one thing : i was compiling my C code with gcc and i got the undeclared error.

Now, compiling with g++ works (exactly same code, same includes and same flags). And the code can be run without problem.

gcc version used : gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)

[display problem, no need of a new message, sorry]

[display problem, no need of a new message, sorry]

Hey,

i got the same compiler error. In fact compiling the code with g++ solves this error. For everyone, who wants to use a c-only compiler … after some time of searching for the declaration of cudaDeviceProp i found the following solution:

.

.

#ifdef __cplusplus

   cudaDeviceProp deviceProp;

#else // !_cplusplus

   struct cudaDeviceProp deviceProp;

#endif

.

.

which solved the problem for me !

hope that helps, cheerz !

1 Like