Integreting CUDA in a static library and then using it

Hello all,

I am getting crazy with a compilation problem, that I am sure it has to be something easy. Hopefully someone of you can help me.

First I have checked this post (The Official NVIDIA Forums | NVIDIA) where a CUDA integration with C++ is very well explained. I did exactly the same but obtaining a static library “.a”

This Makefile looks like below, and it works fine creating the library source .a

[codebox]CUDA_INSTALL_PATH ?= /usr/local/cuda

ROOTDIR ?= /home/chema/NVIDIA_GPU_Computing_SDK/C/src

LIBDIR := $(ROOTDIR)/…/lib

COMMONDIR := $(ROOTDIR)/…/common

INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc

LIB := -L$(CUDA_INSTALL_PATH)/lib -L$(LIBDIR) -L$(COMMONDIR)/lib/linux -lcuda

all: build/source.a

build/source.a: build/source.o build/simpleGPU_launcher.o

ar rcs build/source.a build/*.o

build/source.o: src/source.cpp include/libaco/source.h

g++ -Wall -ansi -I ./include -c src/source.cpp -o build/source.o -O3

build/simpleGPU_launcher.o: src/simpleGPU_launcher.cu

/usr/local/cuda/bin/nvcc --compiler-options -fno-strict-aliasing \

$(INCLUDES) \

	$(LIB)\

-DUNIX -O2 -o build/simpleGPU_launcher.o -c src/simpleGPU_launcher.cu

[/codebox]

After that, in other directory I want to use that library and also compile other files

The makefile looks like this (I have tried to summarized a little bit)

[codebox]bin/source2: source build/source2.o

cp ../../source/trunk/build/source.a lib/

g++ -static build/source2.o -L./lib/ -lsource -o bin/source2

build/source2.o: src/source.cpp

g++ -Wall -ansi -I include/ -c src/source2.cpp -o build/source2.o

source:

make -C ../../source/trunk -f ../../source/trunk/Makefile

[/codebox]

When I use this make file, I have obtained messages like this

tmpxft_00003635_00000000-10_simpleGPU_launcher.ii:(.text+0x69b): undefined reference to `cudaSetDevice’

tmpxft_00003635_00000000-10_simpleGPU_launcher.ii:(.text+0x6b8): undefined reference to `cudaMalloc’

tmpxft_00003635_00000000-10_simpleGPU_launcher.ii:(.text+0x6da): undefined reference to `cudaMemcpy’

I assume that is because it can not link with CUDA lirbaries. However, I tried to use the -L option in the first and second Makefile to indicate the path of the cuda libraries, but it is not working.

Any idea?

Many thanks in advance

Cheers

You aren’t linking in the cuda runtime library anywhere in your application build.

You aren’t linking in the cuda runtime library anywhere in your application build.

Solved, The problem was I was using an old makefile, and the g++ last command to obtain the objective had -static flag. This flag avoids including shared variables such as -lcudart.

Thanks anyway

Solved, The problem was I was using an old makefile, and the g++ last command to obtain the objective had -static flag. This flag avoids including shared variables such as -lcudart.

Thanks anyway