c++cudashared-librariesnvcc

Runtime error when using nVIDIA compiler to generate a shared library for my GNU compiler to link


I want to use nVIDIA compiler to generate a shared library for my GNU compiler to link. Everything goes well until runtime. Following is the detail. Thanks!

main.cpp:

#include <iostream>

using namespace std;

void fcudadriver();

int main()
{
  cout<<"Maine "<<endl;
  fcudadriver();
  return 0;
}

test.cu:

__global__ void fcuda()
{
}

void fcudadriver()
{
  fcuda<<<1,1>>>();
}

Compile:

nvcc --compiler-options '-fPIC' -o libtest.so --shared test.cu
g++ main.cpp -L. -ltest

Run:

./a.out

Results:

./a.out: error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory

Solution

  • . needs to be in your LD_LIBRARY_PATH for the runtime linker to find your shared library.

    Try:

    $ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./a.out