【问题标题】:Problems when linking shared library with GCC [duplicate]将共享库与 GCC 链接时出现问题 [重复]
【发布时间】:2023-03-13 03:55:01
【问题描述】:

我尝试链接刚刚安装在我的系统上的共享库,但由于某种原因,输出不想执行。这是我的汇编:

gcc -o test test.c -lgpio

运行输出时,出现以下错误:

./test: error while loading shared libraries: libgpio-3.0.0.so.3: cannot open shared object file: No such file or directory

这很奇怪,因为我的 /usr/local/lib 文件夹中有这个确切的文件(以及 libgpio-3.0.0.so 和其他共享库文件)。我对 GCC 没有太多经验,所以有人可以解释一下出了什么问题吗?

【问题讨论】:

    标签: c++ c gcc shared-libraries linker-errors


    【解决方案1】:

    您的库文件夹可能不在默认搜索路径中。您需要在编译时使用-L 选项指定它:

    gcc -L /usr/local/lib-folder -o test test.c -lgpio
    

    您还需要在运行程序时将此文件夹添加到LD_LIBRARY_PATH 环境变量中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-27
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 2019-04-19
      • 2012-06-05
      • 2012-01-14
      相关资源
      最近更新 更多