Makefile help Linking kernel file

I am trying to create a simple Makefile that will allow me to have a kernel file seperate from the main file. I know that they do this in the SDK example, but I am trying to avoid common.mk. I have been looking around on the forums and haven’t seen anything to help yet.

My program: main.cu, kernel.cu, matrix.h

Makefile

mult : kernel.o main.o

		nvcc kernel.o main.o -o mult

kernel.o : kernel.cu

		nvcc kernel.cu -c 

main.o : main.cu kernel.cu

		nvcc main.cu -c -o main.o

Main.cu

#include <kernel.cu>

int main(int argc, char* argv[])

{

    //I initialize all variables and everything just fine.

matrixAdd<<<grid, threads>>>(d_C,d_A,d_B,WA);

    return 0;

}

Kernel.cu

#ifndef _KERNEL_H_

#define _KERNEL_H_

#include <stdio.h>

#include <stdlib.h>

#include <cuda.h>

#include "matrix.h" //Header file similar to that in matrixMul example

__global__ void MatrixAdd(double * C, double *A, double * B, int N)

{

	int i = blockDim.x * blockIdx.x + threadIdx.x;

    if (i < N)

        C[i] = A[i] + B[i];

} 

#endif

Whenever I try to make the code I get an error saying matrixAdd is undefined, even though it is included in my main.cu file.

What do I need to change?

If the code is really as you posted it, matrixAdd isn’t defined anywhere. MatrixAdd is though.

Also don’t compile kernel.cu and link the resulting object file, it isn’t necessary and will cause errors.