link error at __host__ __device__ function


I’m implementing a cuda program. But it has two link errors, “error LNK2019: unresolved external symbol” and “fatal error LNK1120: 1 unresolved externals”.

I have several header files(.cuh) and source files(.cu) and my source is like below:


#ifndef _DEF_CUH_

#define _DEF_CUH_

typedef struct vector_1 {

    float v[3];

} vector_1;

typedef struct matrix_1 {

    float m[3][3];

} matrix_1;

typedef struct transMat {

    matrix_1 mat;

    vector_1 vec;

} transMat;


#ifndef _HANDLE_CUH_

#define _HANDLE_CUH_

#include "definition.h"

typedef struct handle{

    transMat tm1;    

    transMat tm2;	

    transMat tm3;  

    transMat tm4;	

    transMat tm5;  	

} handle;

__host__ __device__ handle setHandle(transMat mat);


#include "handle.cuh"

#include "definition.cuh"

#include "funcDec.cuh"

__host__ __device__ handle setHandle(transMat mat) {


	handle res;


	res.tm1= setTransMat(mat);  

                res.tm2= setTransMat();

	res.tm3= setTransMat();

// These functions are declared in "funcDec.cuh" file and defined in "" file.

	return res;


#include "definition.cuh"

#include "funcDec.cuh"

#include "handle.cuh"

int main() {


handle* handles0;

handles0 = (handle*) malloc(sizeof(handle)*100);

transMat mat;


for(i=0; i<100; i++) {

    handles0[i] = setHandle(mat);



if I don’t include “” and just include “handle.cuh”, then link errors occur at setHandle function.

I don’t know how can I solve this problem without including “” file.

Please give me any advice.

Thank you.

It is so weird…
If I include handle.cuh file instead of file and execute this program in the emulation mode, it runs very well.
And in contrast to the case of device mode, including file in emulation mode causes an error by redefinition of the setHandle function.