Why is my shared library not found?

你。 提交于 2019-12-02 03:16:30

问题


I'm trying to compile an example program that links to the shared library produced by Sundown. I'm compiling the program like so.

$ gcc -o sd sundown.c -L. -lsundown

Yet, when I run it I get the following error.

./sd: error while loading shared libraries: libsundown.so: cannot open shared object file: No such file or directory

The output of ls is.

$ ls
libsundown.so  libsundown.so.1  sundown.c  sd

Why is the shared library not found by ld?


回答1:


Short solution:

add . (or whatever it is from your -L flag) to your LD_LIBRARY_PATH. When you run sd, it'll look for libraries in the standard places and the LD_LIBRARY_PATH. Note that since you've added ., this will only work if you run sd from the same directory libsundown.so is in.

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?

You should install libsundown.so in one of the standard places, like /usr/lib or /usr/local/lib. You can do that with an installer or a make file, or something as simple as a INSTALL or README that tells the user to stick the libraries there and ensure the permissions are set to something sensible.



来源:https://stackoverflow.com/questions/11111293/why-is-my-shared-library-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!