nvlink error : Undefined reference to variables

kernel.h

.
.
/* constant variables deceleration */

extern __constant__ uint8_t var1;
extern __constant__ uint8_t var2;
extern __constant__ uint8_t var3;
extern __constant__ uint8_t var4;

_global__ void MyKernel(blah,blah...);
.
.

kernel.cu
_

#include "kernel.h"

_global__ void MyKernel(blah,blah...){

// Here i am using var1,var2,var3,var4
.
.
}

main.cu

{

#include "kernel.h"

.
.
cudaMemcpyToSymbol(var1,...)
cudaMemcpyToSymbol(var2,...)
cudaMemcpyToSymbol(var3,...)
cudaMemcpyToSymbol(var4,...)

/* Call kernel */

MyKernel <<<....>>>
.
.
}

Cuda Separable compilation is ON.

nvcc prompt the linking error for var1,var2,var3,var4 (i.e. undefined reference)

You have no definition for those variables. The statement marked with extern does not define the variable.

Perhaps you don’t understand how extern is used in C++

The first answer here may be useful:

https://stackoverflow.com/questions/10422034/when-to-use-extern-in-c

Thank you.

I haven’t defined the variables at the file scope in main.cu.