gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:07:19 25 4
gpt4 key购买 nike

我想使用 nVIDIA 编译器生成共享库供我的 GNU 编译器链接。一切顺利,直到运行时。以下是详细内容。谢谢!

主要.cpp:

#include <iostream>

using namespace std;

void fcudadriver();

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

测试.cu:

__global__ void fcuda()
{
}

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

编译:

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=$LD_LIBRARY_PATH:. ./a.out

关于c++ - 使用 nVIDIA 编译器生成共享库供我的 GNU 编译器链接时出现运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10044987/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com