码头工人可以解决不匹配的C共享库的问题吗? [英] Can docker solve a problem of mismatched C shared libraries?

查看:85
本文介绍了码头工人可以解决不匹配的C共享库的问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在笔记本计算机上编译的ubuntu(18.04)主机上运行一些haskell代码。

 主机:4.15.0-36-generic#39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU / Linux 

笔记本电脑:4.14.74-1-MANJARO#1 SMP PREEMPT Fri Oct 5 14:16:52 UTC 2018 x86_64 GNU / Linux

我得到的错误是

  /lib/x86_64-linux-gnu/libc.so.6:找不到版本 GLIBC_2.28 

经过一些研究,我了解到这是因为我的笔记本电脑安装了2.28版的glibc,但是主机仅具有libc6 2.27。



我进行了一次谷歌搜索,发现也许docker可以解决这个问题。但是,我只是使用以下Dockerfile创建了一个Docker映像,但它不起作用(相同的GLIBC_2.28错误)

  FROM fpco / stack-build:lts-12.9作为生成器

RUN mkdir / opt / build
COPY。 / opt / build
运行cd / opt / build&&从ubuntu编译堆栈

:18.04
运行mkdir -p / opt / myapp
WORKDIR / opt / myapp
运行apt-get update&& apt-get install -y \
ca证书
COPY --from = builder /opt/build/.stack-work/install/x86_64-linux-tinfo6/lts-12.9/8.4.3 / bin
CMD [ / opt / myapp / myapp-exe]

我不是确定现在该怎么办。我有几个问题:




  • 为什么我首先遇到这个问题?我以为我读过glibc向后兼容的地方? (glibc与libc6是同一件事吗??)


  • 是否可以使用docker解决这个问题?我可以在ubuntu映像中运行构建过程吗?例如 FROM fcpo / stack-build:lts-12.9和ubutu:18.04 ,然后稍后创建另一个将我的二进制文件复制到的ubuntu映像?


  • 是否有人之前遇到过?如果是,您是否找到了解决方案(不仅仅是更改操作系统?)?



解决方案


为什么我首先遇到这个问题?我以为我读过glibc向后兼容的地方?


GLIBC 是向后兼容的(针对旧版GLIBC构建的程序仍可在新版GLIBC上运行),但 inverse 是不正确的。



在您的情况下,您是在较新的(GLIBC-2.28)系统上构建的,并试图在较旧的(GLIBC-2.27)。不能保证能正常工作(尽管对于足够简单的程序来说也可以)。


有没有办法使用docker解决这个问题?


您需要针对计划使用的最旧版本的GLIBC build 。 p>

您可以通过多种方式实现:




  • 使用Linux至较旧的Linux交叉编译器

  • 使用chroot构建环境

  • 在构建时使用具有较旧GLIBC 的Docker容器。



或者您可以在具有程序所需的GLIBC-2.28的Docker容器中运行


I am trying to run some haskell code on an ubuntu (18.04) host, which was compiled on my laptop.

host: 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

laptop: 4.14.74-1-MANJARO #1 SMP PREEMPT Fri Oct 5 14:16:52 UTC 2018 x86_64 GNU/Linux

The error I get is

/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found

After doing some research I learned that this is because my laptop has version 2.28 of glibc installed, but the host only has libc6 2.27.

I did some googling and figured that maybe docker could solve this problem. However, I just created a docker image with the following Dockerfile and it didn't work (same GLIBC_2.28 error)

FROM fpco/stack-build:lts-12.9 as builder

RUN mkdir /opt/build
COPY . /opt/build
RUN cd /opt/build && stack build 

FROM ubuntu:18.04
RUN mkdir -p /opt/myapp
WORKDIR /opt/myapp
RUN apt-get update && apt-get install -y \
  ca-certificates
COPY --from=builder /opt/build/.stack-work/install/x86_64-linux-tinfo6/lts-12.9/8.4.3/bin .
CMD ["/opt/myapp/myapp-exe"]

I'm not sure what to do now. I have a few questions:

  • Why am I getting this problem in the first place? I thought I read somewhere that glibc is backwards compatible? (Is glibc the same thing as libc6..?)

  • Is there a way to use docker to get around this problem? Could i run my build process inside an ubuntu image? e.g. FROM fcpo/stack-build:lts-12.9 and ubutu:18.04, then later on creating another ubuntu image into which i copy my binary?

  • Has anybody else run into this before ? If so did you find a solution (other than just changing operating system?)?

解决方案

Why am I getting this problem in the first place? I thought I read somewhere that glibc is backwards compatible?

GLIBC is backwards compatible (programs built against old GLIBC continue to work on newer GLIBC), but the inverse is not true.

In your case, you built on a newer (GLIBC-2.28) system, and are trying to run on an older one (GLIBC-2.27). That is not guaranteed to work (although it might for sufficiently simple programs).

Is there a way to use docker to get around this problem?

You need to build against the oldest version of GLIBC that you are planning to use.

You can achieve this in multiple ways:

  • use a Linux to older Linux crosscompiler
  • use a chroot build environment
  • use a docker container with older GLIBC at build time.

Or you could run in a docker container that has the GLIBC-2.28 that your program needs.

这篇关于码头工人可以解决不匹配的C共享库的问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆