编译静态库时设置较早的最低内核版本

发布于 2024-10-08 10:34:49 字数 213 浏览 1 评论 0原文

我的发行版(Arch Linux)最近增加了其工具链支持的最低 Linux 内核版本。我正在编译一个静态链接的 Web 应用程序,然后上传到 Web 服务器,而 Web 服务器上的内核版本对于使用新工具链编译的静态库来说太旧了。 (当我尝试在服务器上运行静态二进制文件时,出现分段错误。)是否有一种方法可以使用 GNU 工具链(GCC、binutils、glibc)编译应用程序,从而忽略需要更新内核版本的功能?

My distribution (Arch Linux) recently increased the minimum supported Linux kernel version for its toolchain. I am compiling a web application that I link statically and then upload to a web server, and the kernel version on the web server is too old for static libraries compiled with the new toolchain. (I get a segmentation fault when I try to run static binaries on the server.) Is there a way to compile applications using the GNU toolchain (GCC, binutils, glibc) such that features requiring newer kernel versions are left out?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往日情怀 2024-10-15 10:34:49

Glibc 兼容性实际上只能在一个方向上得到保证。 (较旧的二进制文件可以在较新的系统上运行;反之亦然,但不一定如此。)

为了保证您的二进制文件可以在较旧的系统上运行,请使用较旧的 glibc 进行编译链接。最简单的方法是找到一个较旧的发行版,但我建议设置一个“crosstool ”或类似的交叉编译工具链,目标是与构建系统使用的不同的 libc(这允许跨主机进行可重复构建,无论系统是什么)。

Glibc compatibility is really only guaranteed in one direction. (Older binaries work on newer systems; vice versa, not necessarily so.)

To guarantee that your binaries work on older systems, compile linking with an older glibc. The easiest way to do this is to find an older distribution, but I would recommend setting up a "crosstool" or similar cross-compiling toolchain targeting a different libc than what your build system uses (and this allows for repeatable builds across hosts regardless of what the system is).

带上头具痛哭 2024-10-15 10:34:49

谢谢。我还发现了 glibc 的 --enable-kernel 选项,它可以使用早期的内核。

Thanks. I also found the --enable-kernel option to glibc, which enables working with earlier kernels.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文