如何在docker Image中添加gcc的数学库?

如何在docker Image中添加gcc的数学库?

我正在尝试容器化LuaJIT,Ubuntu 镜像的衍生产品。我安装了 build-essentials,但出现以下编译器错误,提示缺少数学库。已经有-lmMakefile 中的选项。

你能帮我修复这个编译错误吗?谢谢

4eb69afd60 编译错误

gcc main.c -O3 -c -o main.o -I ./LuaJIT/src
gcc main.o -lpthread -lm  -ldl ./LuaJIT/src/libluajit.a -o bench
/usr/bin/ld: ./LuaJIT/src/libluajit.a(lj_vmmath.o): in function `lj_vm_foldarith':
lj_vmmath.c:(.text+0x85): undefined reference to `pow'
/usr/bin/ld: lj_vmmath.c:(.text+0xb5): undefined reference to `atan2'
/usr/bin/ld: ./LuaJIT/src/libluajit.a(lj_vmmath.o): in function `lj_vm_foldfpm':
lj_vmmath.c:(.text+0x161): undefined reference to `cos'
/usr/bin/ld: lj_vmmath.c:(.text+0x169): undefined reference to `tan'
/usr/bin/ld: lj_vmmath.c:(.text+0x1a1): undefined reference to `exp'
/usr/bin/ld: lj_vmmath.c:(.text+0x1a9): undefined reference to `exp2'
/usr/bin/ld: lj_vmmath.c:(.text+0x1b1): undefined reference to `log'
/usr/bin/ld: lj_vmmath.c:(.text+0x1b9): undefined reference to `log2'
/usr/bin/ld: lj_vmmath.c:(.text+0x1c1): undefined reference to `log10'
/usr/bin/ld: lj_vmmath.c:(.text+0x1c9): undefined reference to `sin'
/usr/bin/ld: lj_vmmath.c:(.text+0x1ce): undefined reference to `sqrt'

我可以在主机上毫无问题地构建该项目。

Dockerfile

FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive

# Update the package list
RUN apt-get update

RUN apt-get install -y build-essential
RUN apt-get install -y wget git vim make

RUN git clone https://github.com/vkrasnov/bench_lua.git && cd bench_lua && git checkout 4eb69afd60

WORKDIR /bench_lua

相关内容