I’m working on sprinkling cuda in an open source project (splat hd). I’ve created a static library project in nsight titled “cudapath” with cudapath.cu and cudapath.h with cudapath.cu as follows:
#include
#include
#include
bool cudaCapable(void){
int count;
CUdevice device;
CUcontext context;
cudaGetDeviceCount(&count);
if(count > 0){
cuDeviceGet(&device, 0);
cuCtxCreate(&context, CU_CTX_SCHED_AUTO, device);
size_t free;
size_t total;
cuMemGetInfo(&free, &total);
cuCtxDestroy(context);
if(free / (1024 * 1024) < 468){
printf("Device %d has %d MB free, %d MB total/ Need 468mb\n", 0, free / (1024*1024), total / (1024*1024));
return false;
} else {
return true;
}
} else {
return false;
}
}
This compiles fine and I end up with cudapath/Debug/cudapath.o and cudapath/Debug/libcudapath.a
The other project is a regular C++ project with a G++ toolchain.
I have the project configured as follows:
And the resulting build string & error in the console when building the G++ project:
Invoking: GCC C++ Linker
g++ -L/usr/local/cuda/lib64 -L"/home/sean/cuda-workspace/cudapath/Debug" -march=x86-64 -o "cudasplat" ./itwom3.0.o ./splat.o -lm -lcudart -lcuda -lcudapath -lbz2
/home/sean/cuda-workspace/cudapath/Debug/libcudapath.a(cudapath.o): In function `cudaCapable()':
/home/sean/cuda-workspace/cudapath/Debug/../cudapath.cu:16: undefined reference to `cudaGetDeviceCount'
/home/sean/cuda-workspace/cudapath/Debug/../cudapath.cu:18: undefined reference to `cuDeviceGet'
/home/sean/cuda-workspace/cudapath/Debug/../cudapath.cu:19: undefined reference to `cuCtxCreate_v2'
/home/sean/cuda-workspace/cudapath/Debug/../cudapath.cu:22: undefined reference to `cuMemGetInfo_v2'
/home/sean/cuda-workspace/cudapath/Debug/../cudapath.cu:23: undefined reference to `cuCtxDestroy_v2'
Why can’t it find the cuda functions when the library folder is explicitly specified in the build string? What am I doing wrong?