cpp and cu integration

Hello,

I made a cuda project with cpp and cu files which base on the cppIntegration project from the SDK.
From some reason i get the next compilation error:
error: function “main” has already been defined

but i have main only at the cpp file.

does anyone familiar with this problem?

Thanks!

The error is clear. It seems you already have a function main defined somewhere.

Did you forget update some file of your new project? Did you place a new function main in example in other file and keep the one at the main.cpp ?. A sketch of your files may help to provide a better answer.

Regards!

Thanks,

I have two files: myMain.cpp and wrapsCuda.cu.

i have main in my cpp file and itls look like:

// Includes

#include <stdio.h>

#include <math.h>

#include < iostream>

#include

#include <time.h>

//Host Variables decleration

#define ROWS 5

#define COLUMNS 10

#define Tile_DIM 32

////////////////////////////////////////////////////////////////////////////////

// declaration, forward

extern “C” void func( float* h_A,float *h_y, float lamda, float L,int nb_itr,float tol);

////////////////////////////////////////////////////////////////////////////////

// Program main

int main(){

.

.

func();

.

.

}

and the second file is cu:

#include <stdio.h>

#include <math.h>

#include

#include

#include <time.h>

#include <cublas_v2.h>

#include <myMain.cpp>

extern “C” void func( float* h_A,float *h_y, float lamda, float L,int nb_itr,float tol){

.

.

}

Thanks again

Dont include myMain.cpp in the .cu file.

The extern declaration if enough for the compiler to know where the function is.

Regards.

Thanks,
But i also need the values of ROWS, Tile_DIM and COLUMNS as constant.
If i will not include the cpp file, than i wil have a problem with them at the cu file.

In that case I’ll recommend put your defines, constant, etc in an include file, in example, globals.h which you can include in both, the .cpp and the .cu file.

This is also useful to include other type of stuff, like timing function.

Hope this help.

Thanks a lot!