代码在这里,现在从静态库换成动态库
修改生成库的Makefile文件,修改如下:
INCLUDEFLAG =/usr/local/cuda/include
LDFLAGS=-L /usr/local/cuda/lib64 -lcudart
libstatic_gpu.so:static_gpu.o
g++ -shared -o $@ $^ $(LDFLAGS)
rm -f test/$@
cp $@ test
static_gpu.o:static_gpu.cu
nvcc --compiler-options '-fPIC' $@ -c $^
clean:
rm -f *.o libstatic_gpu.a
测试调用的makefile文件如下:
LDFLAGS=-L. -lstatic_gpu -L /usr/local/cuda/lib64 -lcudart
main: main.o
g++ -o $@ $^ $(LDFLAGS)
main.o: main_static_gpu.cpp
g++ -o $@ -c $^
clean:
rm -f *.o main
只是生成的库,需要放置到LD_LIBRARY_PATH路径下