C++ 使用nVIDIA编译器为我的GNU编译器生成要链接的共享库时出现运行时错误

C++ 使用nVIDIA编译器为我的GNU编译器生成要链接的共享库时出现运行时错误,c++,compiler-construction,cuda,shared-libraries,C++,Compiler Construction,Cuda,Shared Libraries,我想使用nVIDIA编译器生成一个共享库,供GNU编译器链接。在运行之前一切都很顺利。以下是细节。谢谢 main.cpp: #include <iostream> using namespace std; void fcudadriver(); int main() { cout<<"Maine "<<endl; fcudadriver(); return 0; } 运行: 结果: ./a.out: error while loading

我想使用nVIDIA编译器生成一个共享库,供GNU编译器链接。在运行之前一切都很顺利。以下是细节。谢谢

main.cpp:

#include <iostream>

using namespace std;

void fcudadriver();

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

结果:

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

需要位于
LD\u LIBRARY\u路径中
,运行时链接器才能找到共享库

尝试:


这与g++无关。运行时链接器在一组由/etc/ld.so.conf和环境变量ld_LIBRARY_PATH控制的路径中查找共享库。这就是Linux上的工作方式。(setuid程序有一些值得注意的注意事项)参见
manld.so
nvcc --compiler-options '-fPIC' -o libtest.so --shared test.cu
g++ main.cpp -L. -ltest
./a.out
./a.out: error while loading shared libraries: libtest.so: cannot open shared object file: No such file or directory
$ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. ./a.out