我正在尝试编译一个示例程序,该程序链接到Sundown生成的共享库。我正在像这样编译程序。
$ gcc -o sd sundown.c -L. -lsundown
但是,当我运行它时,出现以下错误。
./sd: error while loading shared libraries: libsundown.so: cannot open shared object file: No such file or directory
ls
的输出是。$ ls
libsundown.so libsundown.so.1 sundown.c sd
为什么
ld
找不到共享库?
最佳答案
简短的解决方案:
将.
(或-L
标志中的任何内容)添加到LD_LIBRARY_PATH
中。运行sd
时,它将在标准位置和LD_LIBRARY_PATH中查找库。请注意,由于已添加.
,因此仅当您从libsundown.so所在的同一目录中运行sd
时,此方法才有效。
I plan on distributing the compiled binary. How can I do so that the library can be distributed without forcing people to edit their LD_LIBRARY_PATH?
您应该在标准位置之一中安装libsundown.so,例如/usr/lib或/usr/local/lib。您可以使用安装程序或make文件执行此操作,也可以使用INSTALL或README之类的简单操作来告诉用户将库粘贴在此处,并确保将权限设置为合理的值。
关于gcc - 为什么找不到我的共享库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11111293/