如何在 Ubuntu Linux 上安装共享库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7235798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:56:25  来源:igfitidea点击:

How to install a shared library on Ubuntu Linux?

linuxubuntuinstall

提问by user918545

I'm having trouble shared libraries on my Ubuntu 10.04. I expirienced it several times in the last months, read a lot about installing libs but I seem to miss the point.

我在 Ubuntu 10.04 上共享库时遇到问题。在过去的几个月里,我经历了几次,阅读了很多关于安装库的文章,但我似乎没有抓住重点。

Starting with the source code directory, I run the following commands:

从源代码目录开始,我运行以下命令:

  1. make
    Runs clean, without any error
  2. sudo make install
    Seems to be working fine, ends with: cp foo.so.0.1 /usr/local/lib/
    rm -f /usr/local/lib/foo.so
    ln -s /usr/local/lib/foo.so.0.1 /usr/local/lib/foo.so
  3. sudo ldconfig
    Runs without any output
  1. make
    运行干净,没有任何错误
  2. sudo make install
    似乎工作正常,结尾为: cp foo.so.0.1 /usr/local/lib/
    rm -f /usr/local/lib/foo.so
    ln -s /usr/local/lib/foo.so.0.1 /usr/local/lib/foo.so
  3. sudo ldconfig
    运行没有任何输出

When writing a makefile, I can not address the lib by its name, but by its path:
Not working: -lfoo
Working: -L/usr/local/lib/foo.so

编写 makefile 时,我无法通过名称来寻址 lib,而是通过其路径:
不工作:-lfoo
工作:-L/usr/local/lib/foo.so

The problem stays the same, no matter what lib I try to install.

无论我尝试安装什么库,问题都保持不变。

What am I missing here? Or what can I do to find out?

我在这里缺少什么?或者我能做些什么来找出答案?

回答by nobsid

Is /usr/local/lib/in your library search path? If not you will need to specify both -lfooand /usr/local/lib/in your Makefile, so the linker knows where to look.

是否/usr/local/lib/在您的图书馆搜索路径中?如果不是,则需要在 Makefile 中同时指定-lfoo/usr/local/lib/,以便链接器知道在哪里查找。

Whether or not /usr/local/lib/is in your library search path is dependent on your distribution.

是否/usr/local/lib/在您的库搜索路径中取决于您的发行版。

回答by Saurav Yadav

Remember that the library names should start with liband end with .so. Maybe you are missing the starting lib

请记住,库名称应以 开头lib和结尾.so。也许你错过了开始lib