aarch64-alpine-linux-musl/bin/ld: 找不到 -lpq
aarch64-alpine-linux-musl/bin/ld: cannot find -lpq
当我使用 alpine 作为基础映像构建 Rust 应用程序时,使用此命令:
docker build -f ./Dockerfile -t="reddwarf-pro/reddwarf-admin:v.1.0.0" .
显示错误如下:
#14 222.9 = note: /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lpq
#14 222.9 collect2: error: ld returned 1 exit status
#14 222.9
#14 222.9
#14 223.0 warning: `reddwarf-admin` (bin "reddwarf-admin") generated 1 warning
#14 223.0 error: could not compile `reddwarf-admin` due to previous error; 1 warning emitted
------
executor failed running [/bin/sh -c cargo build --release]: exit code: 101
我已经在alpine镜像中添加了libpq
,为什么还是报错?我应该怎么做才能解决这个问题?这是 Dockerfile:
# to reduce the docker image size
# build stage
FROM rust:1.54-alpine as builder
WORKDIR /app
COPY . /app
RUN rustup default stable
RUN apk update && apk add --no-cache libpq musl-dev pkgconfig openssl-dev gcc
RUN cargo build --release
# RUN cargo build
# Prod stage
FROM alpine:3.15
WORKDIR /app
ENV ROCKET_ADDRESS=0.0.0.0
# ENV ROCKET_PORT=11014
RUN apk update && apk add --no-cache libpq curl
COPY --from=builder /app/.env /app
COPY --from=builder /app/settings.toml /app
COPY --from=builder /app/target/release/reddwarf-admin /app/
COPY --from=builder /app/Rocket.toml /app
CMD ["./reddwarf-admin"]
我也尝试添加 libpq-dev
但似乎 alpine 不包含此库。
你需要的依赖是:
libpq-dev
也许有点令人困惑,开发版本在 v3.14 中称为 postgresql-dev
而不是 libpq-dev
。 (据我所知,它在 v3.15 中被重命名为 libpq-dev
)。
libpq
确实安装了共享库,但是 postgresql-dev
创建了符号 link /usr/lib/libpq.so -> libpq.so.5.13
这使得 linking 成功。
来自man ld
:
On systems which support shared libraries, ld may also
search for files other than libnamespec.a. Specifically, on
ELF and SunOS systems, ld will search a directory for a
library called libnamespec.so before searching for one
called libnamespec.a. (By convention, a ".so" extension
indicates a shared library.) Note that this behavior does
not apply to :filename, which always specifies a file called
filename.
也就是说,-lname
语法将只搜索 libname.(a|so)
,而不是版本名称。
当我使用 alpine 作为基础映像构建 Rust 应用程序时,使用此命令:
docker build -f ./Dockerfile -t="reddwarf-pro/reddwarf-admin:v.1.0.0" .
显示错误如下:
#14 222.9 = note: /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lpq
#14 222.9 collect2: error: ld returned 1 exit status
#14 222.9
#14 222.9
#14 223.0 warning: `reddwarf-admin` (bin "reddwarf-admin") generated 1 warning
#14 223.0 error: could not compile `reddwarf-admin` due to previous error; 1 warning emitted
------
executor failed running [/bin/sh -c cargo build --release]: exit code: 101
我已经在alpine镜像中添加了libpq
,为什么还是报错?我应该怎么做才能解决这个问题?这是 Dockerfile:
# to reduce the docker image size
# build stage
FROM rust:1.54-alpine as builder
WORKDIR /app
COPY . /app
RUN rustup default stable
RUN apk update && apk add --no-cache libpq musl-dev pkgconfig openssl-dev gcc
RUN cargo build --release
# RUN cargo build
# Prod stage
FROM alpine:3.15
WORKDIR /app
ENV ROCKET_ADDRESS=0.0.0.0
# ENV ROCKET_PORT=11014
RUN apk update && apk add --no-cache libpq curl
COPY --from=builder /app/.env /app
COPY --from=builder /app/settings.toml /app
COPY --from=builder /app/target/release/reddwarf-admin /app/
COPY --from=builder /app/Rocket.toml /app
CMD ["./reddwarf-admin"]
我也尝试添加 libpq-dev
但似乎 alpine 不包含此库。
你需要的依赖是:
libpq-dev
也许有点令人困惑,开发版本在 v3.14 中称为 postgresql-dev
而不是 libpq-dev
。 (据我所知,它在 v3.15 中被重命名为 libpq-dev
)。
libpq
确实安装了共享库,但是 postgresql-dev
创建了符号 link /usr/lib/libpq.so -> libpq.so.5.13
这使得 linking 成功。
来自man ld
:
On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a ".so" extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.
也就是说,-lname
语法将只搜索 libname.(a|so)
,而不是版本名称。