简体   繁体   English

如何根据libstdc ++库安装程序

[英]How to install the program depending on libstdc++ library

My program is written in C++, using GCC on Ubuntu 9.10 64 bit. 我的程序是用C ++编写的,在Ubuntu 9.10 64位上使用GCC。 If depends on /usr/lib64/libstdc++.so.6 which actually points to /usr/lib64/libstdc++.so.6.0.13. 如果取决于/usr/lib64/libstdc++.so.6,则实际上指向/usr/lib64/libstdc++.so.6.0.13。 Now I copy this program to virgin Ubuntu 7.04 system and try to run it. 现在,我将此程序复制到原始Ubuntu 7.04系统并尝试运行它。 It doesn't run, as expected. 它没有按预期运行。 Then I add to the program directory the following files: 然后,将以下文件添加到程序目录:

  • libstdc++.so.6.0.13 的libstdc ++。so.6.0.13
  • libstdc++.so.6 (links to libstdc++.so.6.0.13) libstdc ++。so.6(链接到libstdc ++。so.6.0.13)

Execute command: 执行命令:

LD_LIBRARY_PATH=. ./myprogram

Now everything is OK. 现在一切正常。 The question: how can I write installation script for such program? 问题:如何编写此类程序的安装脚本? myprogram file itself should be placed to /usr/local/bin. myprogram文件本身应放在/ usr / local / bin中。 What can I do with dependencies? 我该如何处理依赖关系? For example, on destination computer, /usr/lib64/libstdc++.so.6 link points to /usr/lib64/libstdc++.so.6.0.8. 例如,在目标计算机上,/ usr / lib64 / libstdc ++。so.6链接指向/usr/lib64/libstdc++.so.6.0.8。 What can I do with this? 我该怎么办?

Note: the program is closed-source, I cannot provide source code and makefile. 注意:该程序是封闭源代码,我无法提供源代码和makefile。

If you're working on Ubuntu, making a .deb ( Debian Package ) seems to way to go. 如果您正在使用Ubuntu,那么制作.deb( Debian软件包 )似乎还有路要走。 Here is a link to get you started. 是一个入门的链接。

Your package will state it depends on some other packages (typically the packages that includes libstdc++.so.6.0.13 - i guess the package name is something like libstdc++ ) and dependencies will be installed when you install your own package using dpkg -i <yourpackage>.deb . 您的软件包将声明它依赖于其他软件包(通常包括libstdc++.so.6.0.13的软件包-我猜软件包名称类似于libstdc++ ),并且当您使用dpkg -i <yourpackage>.deb

Afterwards, you'll be able to uninstall it using dpkg -r <yourpackage> . 之后,您将可以使用dpkg -r <yourpackage>卸载它。

Anyway, never ship such standards files with your own archive. 无论如何, 切勿将此类标准文件与您自己的存档一起提供。 Dependencies exists for this exact purpose. 存在依赖关系用于此确切目的。

Hope it helps. 希望能帮助到你。

The real problem is that you try to install a binary that use newer versions os common libraries that the ones available on Ubuntu 9.10. 真正的问题是您尝试安装使用较新版本的二进制文件或在Ubuntu 9.10上可用的公共库。 The best option should be to make a specific target for the old Ubuntu 7.10 an compile it with the old libraries (that's a backport). 最好的选择应该是为旧的Ubuntu 7.10制定一个特定的目标,并使用旧的库对其进行编译(这是一个反向端口)。

Then you should make two (or more) .deb packages, one for Ubuntu 9.10 and one for Ubuntu 7.10. 然后,您应该制作两个(或更多).deb软件包,一个用于Ubuntu 9.10,一个用于Ubuntu 7.10。

Another possibility is to continue doing what you are doing now : set LD_LIBRARY_PATH to point to the desired version of libstdc++ and other necessary libraries. 另一种可能性是继续做您现在正在做的事情:将LD_LIBRARY_PATH设置为指向所需的libstdc ++版本和其他必要的库。 You just set this environment variable in a launcher shell script. 您只需在启动程序Shell脚本中设置此环境变量。 In you script you check if the new libraries are available or not and you set your LB_LIBRARY_PATH (say to /usr/local/lib/myprogram/) only if needed. 在脚本中,您检查新库是否可用,并且仅在需要时才设置LB_LIBRARY_PATH(例如/ usr / local / lib / myprogram /)。 But as others poster pointed out : that's a very bad practice. 但是正如其他张贴者指出的那样:这是非常糟糕的做法。 Anyway, never try to put these provided libraries at their standard place in Ubuntu 9.10, you would risk broking the target system and causing update problems for users or your program if these libraries are officially backported someday. 无论如何,永远不要尝试将这些提供的库放在Ubuntu 9.10中的标准位置,如果有朝一日正式将这些库正式移植,则可能会冒险破坏目标系统并给用户或程序造成更新问题。

But if you choose to include your own set of system libraries there is still another way to go than the above one: just link these libraries statically. 但是,如果您选择包括自己的系统库集,那么除了上述方法之外,还有另一种方法:只需静态链接这些库即可。 If a program is the only user of a library as it will probably be in the above scenario you'll lose all advantages of using a shared dynamic library, then why bother with using it at all ? 如果程序是库的唯一用户(如在上述情况下那样),您将失去使用共享动态库的所有优势,那为什么还要麻烦地使用它呢? And with stacically linked libraries you won't have to install them. 使用固定链接的库,您无需安装它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM