I'm trying to build the following program:
#include <iostream>
#include <cuda.h>
int main() {
const char* str;
auto status = cuInit(0);
cuGetErrorString(status, &str);
std::cout << "status = " << str << std::endl;
int device_id = 0;
CUcontext primary_context_id;
status = cuDevicePrimaryCtxRetain(&primary_context_id, device_id);
cuGetErrorString(status, &str);
std::cout << "status = " << str << std::endl;
status = cuDevicePrimaryCtxRelease(device_id);
cuGetErrorString(status, &str);
std::cout << "status = " << str << std::endl;
}
Compilation always goes fine; but, with CUDA 10.2, linking works, while with CUDA 11.2, I get:
/usr/bin/ld: a.o: in function `main':
a.cpp:(.text+0xcc): undefined reference to `cuDevicePrimaryCtxRelease_v2'
collect2: error: ld returned 1 exit status
Why is this happening and how can I fix it?
Note: I'm using Devuan Beowulf with driver version 440.82 (have not installed a new driver for CUDA 11.2).