Certain cuSparse functions can't be found by compiler

When running this code:

#include <stdio.h>
#include <cusparse.h>

int main() {
    cusparseHandle_t handle;  // THIS WORKS
    cusparseStatus_t status = cusparseCreate(&handle);  // DOESN'T WORK

    cusparseDestroy(handle); // DOESN'T WORK
    return 0;
}

I get errors for the functions cusparseCreate() and cusparseDestroy(). The error reads: “unresolved external symbol [function name] referenced in function main”.

I get no errors for including the cuSparse.h library, nor if I run code which only intializes the variables handle and status. To be clear, I mean that this code compiles and runs properly:

#include <stdio.h>
#include <cusparse.h>

int main() {
    cusparseHandle_t handle;  // THIS WORKS
    cusparseStatus_t status; // THIS WORKS

    return 0;
}

This implies to me that error is not with the library, but for someone reason my compiler can’t find the functions.

I am using Visual Studio 2022 with the built-in CUDA toolkit. I can use the standard cuda_runtime.h library without issue. Does anyone know why I’m having issues with the cuSparse library? I’d appreciate any assistance, as I’m stuck until this gets resolved.

You need to link against the cusparse library.
nvcc my_cusparse_app.cu -lcusparse -o my_cusparse_app

1 Like