在这里我以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_G