CUDA Makefile (Windows 64-bit)

I spent a while getting a makefile going for windows 64-bit so I could use an IDE like Eclipse. I don’t exactly remember the steps required, but this will surely help one or two people out. Before you get too excited, I have not detailed my steps and you need some sort of experience working in this type of environment. There is no magical exe to run, although these steps aren’t exactly hard.

You NEEEED Visual Studio 2008 Professional Edition installed for 64-bit compiling. Express Edition will probably work for 32-bit, but will not for 64-bit because it does not come with the 64-bit compilers. The Windows SDK (aka the free version) will not work because, while it comes with the necessary compilers, CUDA is not fully configured to see it and will complain about an invalid compiler. There is probably a work around, more than likely based on the environment .bat files. Of course, you need the CUDA Toolkit and SDK installed. I am using the 64-bit versions, but porting it to 32-bit should not be difficult.

I am also using MinGW, but any GNU Make program will work. Eclipse is set up to use “mingw32-make” to compile the project, and you need to specify the correct include directories if you want syntax highlighting. Those include directories are referenced in the Makefile and you should be able to input them through the Eclipse options page. cl.exe secretly includes another directory, so for proper highlighting add:

C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include

I have some environment variables set, and while I think that all of them are automatically set, there is a chance that I made them:

    CUDA_BIN_PATH

    CUDA_INC_PATH

    CUDA_LIB_PATH

    NVSDKCOMPUTE_ROOT

    NVSDKCUDA_ROOT

My path also includes the bin64 directory of the CUDA toolkit, but again, I was under the impression that it was automatically added.

The makefile:

VCDIR = C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC

INCPATH = -I"$(VCDIR)/include" -I"$(NVSDKCUDA_ROOT)\common\inc"

LIBPATH = -L"$(VCDIR)/lib/amd64" -L"$(NVSDKCUDA_ROOT)\common\lib"

LIBS = -lcutil64D -lglut64 -lglew64

SRCDIR = src

BINDIR = bin

export compiler-bindir = $(VCDIR)/bin

export CUDA_PROFILE = 0

#export CUDA_PROFILE_CONFIG = cuda_profile.cfg

$(BINDIR)/%.obj : $(SRCDIR)/%.c*

	nvcc -c $< $(INCPATH) -o $@ 

SRC = $(basename $(notdir $(wildcard $(SRCDIR)/*.c*)))

OBJECTS = $(addsuffix .obj, $(addprefix $(BINDIR)/, $(SRC)))

APP	 = $(BINDIR)/app.exe

all: $(APP)

$(APP): $(OBJECTS) 

	nvcc $(OBJECTS) $(LIBPATH) $(LIBS) -o $(APP)

	$(APP)

clean:  

	rm $(OBJECTS) *.dep

I’m not the greatest with Makefiles, but it works. This does not take in .h dependencies because I could not get it to work, but is not such a big deal anyway (for me, at least). “cudart” is automatically linked by nvcc (the cuda compiler), but add it to the list of libraries if this is not true for your compiler. You need to make a folder called “src” and a folder called “bin”. Of course, you could always just edit the makefile to get around this, but there is a lot of junk generated by the build and it’s best to keep them seperate.

Also, the Eclipse syntax highlighting will not fully appreciate .cu files. This will mostly fix it:

#ifdef __CDT_PARSER__

	#define __device__

	#define __global__

	#define __shared__

	#define __host__

#endif

Let me know if any errors pop up. Setting up this environment took me a while, and while I don’t have the time to write a more in-depth guide, I will more than likely have run into your error once or twice before.