Makefile:
hello_dlsym: hello_dlsym.cpp
g++ $< -o $@ -ldl
hello_dlsym.cpp
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#define LIB_CACULATE_PATH "../library/libcusolver.so"
typedef int (*CAC_FUNC)(int, int);
int main()
{
void *handle;
char *error;
CAC_FUNC cac_func = NULL;
handle = dlopen(LIB_CACULATE_PATH, RTLD_LAZY);
if (!handle) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
dlerror();
*(void **) (&cac_func) = dlsym(handle, "cusolverSpCcsrlsvqr");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(EXIT_FAILURE);
}
dlclose(handle);
exit(EXIT_SUCCESS);
}