Linux下创建CUDA程序动态链接库示例

来源:互联网 发布:python 日志 编辑:程序博客网 时间:2024/06/12 00:42

在这里我以SDK中自带的deviceQuery.cpp文件为里,利用t.cpp来调用其编译生成的动态链接库。

 

首先创建一个soTest的文件夹,里面有两个文件deviceQuery.cpp, t.cpp。

 

deviceQuery.cpp的代码可以参考CUDASDK t.cpp的源代码如下:

 

#include int cudev(int argc, char** argv);

int main(int argc, char ** argv)

{

   cudev(argc,argv); 

   return 0;

}

 

 然后在当前目录下输入以下命令:

 

1. g++ -W -Wall -Wimplicit -Wswitch -Wformat -Wchar-subscripts -Wparentheses -Wmultichar -Wtrigraphs -Wpointer-arith -Wcast-align -Wreturn-type -Wno-unused-function -fno-strict-aliasing -I. -I/usr/local/cuda/include -I/home/cuda/NVIDIA_GPU_Computing_SDK/C/common/inc -DUNIX -O2 -o deviceQuery.o -c deviceQuery.cpp

 

2. g++ -shared -Wl,-soname,libcudev.so.1 -o libcudev.so.1.0.0 deviceQuery.o -lc -I. -I/usr/local/cuda/include -I/home/cuda/NVIDIA_GPU_Computing_SDK/C/common/inc -L/usr/local/cuda/lib -L/home/cuda/NVIDIA_GPU_Computing_SDK/C/lib -L/home/cuda/NVIDIA_GPU_Computing_SDK/C/common/lib/linux -lcudart -L/usr/local/cuda/lib -L/home/cuda/NVIDIA_GPU_Computing_SDK/C/lib -L/home/cuda/NVIDIA_GPU_Computing_SDK/C/common/lib/linux -lcutil

 

3. gcc -Wall -o t.o -c t.c

 

4. ln -sf libcudev.so.1.0.0 libcudev.so

 

5. ln -sf libcudev.so.1.0.0 libcudev.so.1

 

6. gcc -Wall -L. -o t t.o -lcudev

 

这样执行 ./t 就可以顺利调用deviceQuery.cpp中的函数了^_^