problem with typedef struct in header file error: invalid redeclaration of type nam

Hi,

I tried to put something like this

typedef struct {
int width;
int height;
int pitch;
float* elements;
}matrix;

in a header file and include the header file in my .cu file.
When I compile my .cu file with -include the .h file.
I get:

error: invalid redeclaration of type name “matrix”

Any help would be appreciated, thanks.

Have you tried to put
#pragma once
in the beginning?

I added the line.

Now I get this:

./myMatrixMult1.h:17: error: using typedef-name ‘matrix’ after ‘struct’

./myMatrixMult1.h:22: error: ‘matrix’ has a previous declaration here

./myMatrixMult1.h:22: error: invalid type in declaration before ‘;’ token

./myMatrixMult1.h:22: error: conflicting declaration ‘typedef int matrix’

./myMatrixMult1.h:22: error: ‘matrix’ has a previous declaration as ‘typedef struct matrix matrix’

make: *** [myMatrixMult1] Error 255

Whenever I put the typedef struct in the .cu, it worked.

hi,

In julia set program an error have occur when i build the program, " invalid redeclaration of type name “cuComplex”
"

i have added all required header files…help me please

are you including cuComplex.h in your code and also have a typedef for the cuComplex type?

If so, that is the problem. You can probably just get rid of the typedef.

this is the julia set program…

#pragma once
#include <stdio.h>
#include<cuda.h>
#include<stdint.h>
#include <GL/glut.h>
#include <vector_types.h>
#include “cuComplex.h”
#include<time.h>
#include
#include “cuda_runtime.h”
#include “device_launch_parameters.h”
#include “cpu_bitmap.h”
#define DIM 1000

struct cuComplex{
float r;
float i;
cuComplex( float a, float b ) : r(a), i(b) {}
device float magnitude2( void ) {
return r * r + i * i;
}
device cuComplex operator*(const cuComplex& a) {
return cuComplex(ra.r - ia.i, ia.r + ra.i);
}
device cuComplex operator+(const cuComplex& a) {
return cuComplex(r+a.r, i+a.i);
}
};
device int julia( int x, int y ) {
const float scale = 1.5;
float jx = scale * (float)(DIM/2 - x)/(DIM/2);
float jy = scale * (float)(DIM/2 - y)/(DIM/2);
cuComplex c(-0.8, 0.156);
cuComplex a(jx, jy);
int i = 0;
for (i=0; i<200; i++) {
a = a * a + c;
if (a.magnitude2() > 1000)
return 0;
}
return 1;
}

global void kernel( unsigned char ptr ) {
// map from threadIdx/BlockIdx to pixel position
int x = blockIdx.x;
int y = blockIdx.y;
int offset = x + y * gridDim.x;
// now calculate the value at that position
int juliaValue = julia( x, y );
ptr[offset
4 + 0] = 255 * juliaValue;
ptr[offset4 + 1] = 0;
ptr[offset
4 + 2] = 0;
ptr[offset*4 + 3] = 255;
}
int main( void ) {
CPUBitmap bitmap( DIM, DIM );
unsigned char dev_bitmap;
cudaMalloc( (void
*)&dev_bitmap,bitmap.image_size() );
dim3 grid(DIM,DIM);
kernel<<<grid,1>>>( dev_bitmap );
cudaMemcpy( bitmap.get_ptr(), dev_bitmap,bitmap.image_size(),
cudaMemcpyDeviceToHost ) ;
bitmap.display_and_exit();
cudaFree( dev_bitmap ) ;
}

and error showing…

C:/Users/BRIJ KUMAR/Documents/Visual Studio 2010/Projects/A10/A10/kernel.cu(16): error : invalid redeclaration of type name “cuComplex”
1> C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\include\cuComplex.h(282): here

i can’t understand what the problem here…tell me please

this is the program …when i build solution …an error has ocure

#ifndef GPU_ANIM_H
#define GPU_ANIM_H
#include “gl_helper.h”
#include “cuda_runtime.h”
#include “cuda.h”
#include “cuda_gl_interop.h”
#include
#include “device_launch_parameters.h”
#include<stdio.h>

using namespace std;

PFNGLBINDBUFFERARBPROC glBindBuffer = NULL;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffers = NULL;
PFNGLGENBUFFERSARBPROC glGenBuffers = NULL;
PFNGLBUFFERDATAARBPROC glBufferData = NULL;

struct GPUAnimBitmap {
GLuint bufferObj;
cudaGraphicsResource *resource;
int width, height;
void dataBlock;
void (fAnim)(uchar4,void
,int);
void (animExit)(void);
void (clickDrag)(void,int,int,int,int);
int dragStartX, dragStartY;

GPUAnimBitmap( int w, int h, void *d = NULL ) {
    width = w;
    height = h;
    dataBlock = d;
    clickDrag = NULL;

    // first, find a CUDA device and set it to graphic interop
    cudaDeviceProp  prop;
    int dev;
    memset( &prop, 0, sizeof( cudaDeviceProp ) );
    prop.major = 1;
    prop.minor = 0;
    cudaChooseDevice( &dev, &prop );
    cudaGLSetGLDevice( dev );

    // a bug in the Windows GLUT implementation prevents us from
    // passing zero arguments to glutInit()
    int c=1;
    char* dummy = "";
    glutInit( &c, &dummy );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA );
    glutInitWindowSize( width, height );
    glutCreateWindow( "bitmap" );

    glBindBuffer    = (PFNGLBINDBUFFERARBPROC)GET_PROC_ADDRESS("glBindBuffer");
    glDeleteBuffers = (PFNGLDELETEBUFFERSARBPROC)GET_PROC_ADDRESS("glDeleteBuffers");
    glGenBuffers    = (PFNGLGENBUFFERSARBPROC)GET_PROC_ADDRESS("glGenBuffers");
    glBufferData    = (PFNGLBUFFERDATAARBPROC)GET_PROC_ADDRESS("glBufferData");

    glGenBuffers( 1, &bufferObj );
    glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, bufferObj );
    glBufferData( GL_PIXEL_UNPACK_BUFFER_ARB, width * height * 4,
                  NULL, GL_DYNAMIC_DRAW_ARB );

    cudaGraphicsGLRegisterBuffer( &resource, bufferObj, cudaGraphicsMapFlagsNone );
}

~GPUAnimBitmap() {
    free_resources();
}

void free_resources( void ) {
    cudaGraphicsUnregisterResource( resource ) ;

    glBindBuffer( GL_PIXEL_UNPACK_BUFFER_ARB, 0 );
    glDeleteBuffers( 1, &bufferObj );
}


long image_size( void ) const { return width * height * 4; }

void click_drag( void (*f)(void*,int,int,int,int)) {
    clickDrag = f;
}

void anim_and_exit( void (*f)(uchar4*,void*,int), void(*e)(void*) ) {
    GPUAnimBitmap**   bitmap = get_bitmap_ptr();
    *bitmap = this;
    fAnim = f;
    animExit = e;

    glutKeyboardFunc( Key );
    glutDisplayFunc( Draw );
    if (clickDrag != NULL)
        glutMouseFunc( mouse_func );
    glutIdleFunc( idle_func );
    glutMainLoop();
}

error…

------ Build started: Project: A9, Configuration: Debug Win32 ------
1>Build started 19/08/2016 4:12:40 PM.
1>InitializeBuildStatus:
1> Touching “Debug\A9.unsuccessfulbuild”.
1>AddCudaCompileDeps:
1>Skipping target “AddCudaCompileDeps” because all output files are up-to-date with respect to the input files.
1>AddCudaCompilePropsDeps:
1>Skipping target “AddCudaCompilePropsDeps” because all output files are up-to-date with respect to the input files.
1>CudaBuild:
1>Skipping target “CudaBuild” because all output files are up-to-date with respect to the input files.
1>LINK : fatal error LNK1561: entry point must be defined
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.66
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

what is fatal error in this program …pls help me