ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.86k stars 2.55k forks source link

Cross linking with alpine v3.20 gmp 6.3.0-r1 failed with `undefined symbol: __gmp_set_memory_functions`, but linking use gmp 6.2.1-r3 still keep working (Host is Arch linux) #21112

Open zw963 opened 2 months ago

zw963 commented 2 months ago

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

I create a new project for reproduce this issue easier, it should runable on linux.

  1. clone https://github.com/zw963/zig_cc_reproduce_issue
  2. cd project folder, run ./run.sh, as you can see, it will static linking some libraries in the x86_64-linux-musl folder, but failed with following error message.
 ╰─ $ 130  cc -target x86_64-linux-musl ./bin/college.o -o ./bin/college -static -L$PWD/x86_64-linux-musl -lgmp -lyaml -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lpcre2-8 -lgc -lpthread -ldl -levent -lunwind
ld.lld: error: undefined symbol: __gmp_set_memory_functions
>>> referenced by main_module
>>>               ./bin/college.o:(__crystal_main)
  1. above issue caused by x86_64-linux-musl/libgmp.a, gmp version 6.3.0-r1, it download and extract from here

  2. if copy libgmp.a in the project root(version 6.2.1-r3, download from here into x86_64-linux-musl/libgmp.a override it, then ./run.sh again, it works now.

Expected Behavior

It should linking with gmp 6.3.0-r1, because all others package use alpine v3.20's version, but only gmp keep stopping on 6.2.1-r3 which belongs to alpine v3.18.

EDIT: if cross linking for darwin, with gmp 6.3.0, it works!

Thanks.

zw963 commented 1 month ago

Is it that I didn't describe the issue accurately?