我正在尝试将我的 Rust crate 构建为静态库,以便通过 FFI 在 Golang 中进一步使用它。到目前为止,尝试了许多关于链接的不同方法,但undefined reference最终 go 二进制文件仍然存在错误:
/usr/bin/ld: ./lib/libsolana_mint.a(nix-6da6fd938c826d01.nix.e161731d-cgu.5.rcgu.o): in function `nix::mqueue::mq_open':
nix.e161731d-cgu.5:(.text._ZN3nix6mqueue7mq_open17hd889faf637ea61f3E+0xd): undefined reference to `mq_open'
/usr/bin/ld: nix.e161731d-cgu.5:(.text._ZN3nix6mqueue7mq_open17hd889faf637ea61f3E+0x1e): undefined reference to `mq_open'
/usr/bin/ld: ./lib/libsolana_mint.a(nix-6da6fd938c826d01.nix.e161731d-cgu.5.rcgu.o): in function `nix::mqueue::mq_unlink':
nix.e161731d-cgu.5:(.text._ZN3nix6mqueue9mq_unlink17hc51e2d94961b863cE+0x6): undefined reference to `mq_unlink'
/usr/bin/ld: ./lib/libsolana_mint.a(nix-6da6fd938c826d01.nix.e161731d-cgu.5.rcgu.o): in function `nix::mqueue::mq_close':
nix.e161731d-cgu.5:(.text._ZN3nix6mqueue8mq_close17h53f48d4def20adadE+0x3): undefined reference to `mq_close'
所有错误都引用了来自依赖项的一堆 Rust crate,例如nix,solana_sdk
这是我的 Dockerfile,我从中构建它:
# syntax=docker/dockerfile:1
FROM rust:1.58 as build
RUN apt-get update
RUN apt-get install -y libudev-dev && apt-get install -y pkg-config
WORKDIR /solana
COPY lib/solana_mint ./solana_mint
WORKDIR /solana/solana_mint
RUN RUSTFLAGS='-C target-feature=+crt-static' cargo build --target x86_64-unknown-linux-gnu --release
FROM golang:1.17
WORKDIR /cardforge
COPY --from=build /solana/solana_mint/target/release/libsolana_mint.a ./lib/
COPY ./lib/solana_mint.h ./lib/
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY controllers ./controllers
COPY models ./models
COPY *.go ./
RUN go build main.go
EXPOSE 8080
CMD [ "RUST_LOG=trace ./main" ]
将不胜感激任何信息,因为cgo高级示例的资源不多,除了普通的 hello-workd 与单函数绑定
汪汪一只猫
相关分类