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 I have been looking around on the forums and haven’t seen anything to help yet.

My program:,, matrix.h


mult : kernel.o main.o

		nvcc kernel.o main.o -o mult

kernel.o :

		nvcc -c 

main.o :

		nvcc -c -o main.o

#include <>

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;


#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];



Whenever I try to make the code I get an error saying matrixAdd is undefined, even though it is included in my 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 and link the resulting object file, it isn’t necessary and will cause errors.