英文:
Can I build Postgres 15 binaries on Linux so that they work on any distribution?
问题
以前,Postgres 10的二进制文件可以从网站下载,它们可以在任何Linux上运行。我需要以相同的方式构建Postgres 15的二进制文件,以便它们可以在任何发行版上运行。
cd /home/username/postgres-15/build_postgres
../configure --prefix=/home/username/postgres-15/install
make
make install
我尝试在Ubuntu 16中构建,但在Centos 7中无法工作。我尝试在Centos 7中构建,它可以在Ubuntu 16中工作,但现在在Ubuntu 22中无法工作(加载共享库时出错: libldap_r-2.4.so.2: 无法打开共享对象文件: 没有那个文件或目录)。
是否可能进行通用编译?
英文:
Previously, binary files of Postgres 10 could be downloaded from the site and they worked on any Linux. I need to build binaries for Postgres 15 in the same way so that they work on any distributions.
cd /home/username/postgres-15/build_postgres
../configure --prefix=/home/username/postgres-15/install
make
make install
I tried to build in Ubuntu 16, but it doesn't work in Centos 7. I tried to build in Centos 7 and it worked for Ubuntu 16, but now it doesn't work in Ubuntu 22 (error while loading shared libraries: libldap_r-2.4.so.2: cannot open shared object file: No such file or directory).
Is it possible to make a universal assembly ?
答案1
得分: 2
建立一个“通用二进制”在涉及共享库时几乎是不可能的,因为不同的发行版(以及发行版版本)可能具有不兼容的库版本(正如您在问题中看到的libldap
)。
您最好的选择是创建一个自包含的软件包,其中包括二进制文件和任何必要的库。这在许多情况下都有效。
最简单的解决方案是在容器中运行您的服务,因为这样可以完全控制对服务可见的运行时环境。在CentOS 7、Fedora 38、Ubuntu 22等系统上,我可以运行docker run -d -e POSTGRES_PASSWORD=secret postgres:15
。如果选择这个选项,已经为您完成了工作;您只需使用官方的postgres
镜像。
除了容器,还可以考虑使用类似AppImage的替代方案,这是一种专门用于解决您遇到的问题的分发格式。我自己从未开发过AppImage,所以无法对其易用性发表评论。
我建议只使用官方的postgres
容器,然后就可以了。
英文:
Building a "universal binary" is effectively impossible when there are shared libraries involved, because different distributions (and distribution versions) may have incompatible versions of the library (as you see with libldap
in your question).
Your best option is creating a self contained package that includes both the binary and any necessary libraries. This will work in many cases.
The simplest solution is to run your service in a container, because this gives you complete control over the runtime environment visible to the service. I can docker run -d -e POSTGRES_PASSWORD=secret postgres:15
on CentOS 7, Fedora 38, Ubuntu 22, etc. If you choose this option, the work has already been done for you; you can just use the official postgres
image.
Alternatives to containers would be something like AppImage, a distribution format created to solve exactly the problem you've encountered. I've never developed an appimage myself, so I can't really comment on ease of use.
I would just use the official postgres
container and be done with it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论