cgo static build failed of "undefined reference to `__longjmp_chk'"
Describe the bug
wasmer-go is vendored in my private golang project, for removing unnecessary dependencies, I was trying to build my project with wasmer in cgo static build mode but failed, can you give me some guide how to make it work?
Steps to reproduce
- Download
github.com/wasmerio/wasmer, cd wasmer dir,git checkout -b v2.0.0 2.0.0switch to 2.0.0 release. - run
maketo compile, got result as
$ ls -l target/release/
total 105164
drwxrwxr-x 83 zhangwei zhangwei 4096 7ζ 20 12:18 build
drwxrwxr-x 2 zhangwei zhangwei 61440 7ζ 20 15:06 deps
drwxrwxr-x 2 zhangwei zhangwei 4096 7ζ 20 12:13 examples
drwxrwxr-x 2 zhangwei zhangwei 4096 7ζ 20 12:13 incremental
-rw-rw-r-- 2 zhangwei zhangwei 65665232 7ζ 20 15:06 libwasmer_c_api.a
-rw-rw-r-- 1 zhangwei zhangwei 21444 7ζ 20 13:08 libwasmer_c_api.d
-rw-rw-r-- 2 zhangwei zhangwei 2604244 7ζ 20 15:06 libwasmer_c_api.rlib
-rwxrwxr-x 2 zhangwei zhangwei 15421464 7ζ 20 15:06 libwasmer_c_api.so
-rwxrwxr-x 2 zhangwei zhangwei 23861096 7ζ 20 15:02 wasmer
-rw-rw-r-- 1 zhangwei zhangwei 23199 7ζ 20 12:18 wasmer.d
- In my own project, "wasmer-go" master code is vendored, commit id:
72b0251581c7 - Compile my own code in my Makefile with command
CGO_CFLAGS="-I/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/lib/c-api/" \
CGO_LDFLAGS="-Wl,-rpath,/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release/ -L/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release/ -pthread -lwasmer_c_api -lm -ldl -static" \
CC=/usr/bin/musl-gcc \
go build -mod vendor -tags custom_wasmer_runtime -ldflags "-X xxx.GitCommit="xxx" -X xxx.Version=xxx" -o <bin> .
Expected behavior
The compilation should succeed and binary should be compiled as static.
Actual behavior
Got compilation error:
# github.com/wasmerio/wasmer-go/wasmer
/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release//libwasmer_c_api.a(handlers.o): In function `wasmer_unwind':
handlers.c:(.text.wasmer_unwind+0xa): undefined reference to `__longjmp_chk'
/home/zhangwei/program/gocode/src/github.com/wasmerio/wasmer/target/release//libwasmer_c_api.a(std-b1047a2788193be4.std.b9wtcb8n-cgu.0.rcgu.o): In function `std::sys::unix::net::on_resolver_failure':
/rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0//library/std/src/sys/unix/net.rs:453: undefined reference to `__res_init'
collect2: error: ld returned 1 exit status
Makefile:26: recipe for target 'bin' failed
make: *** [bin] Error 2
Can you give me some tips how to make it work? Thanks in advance!
Hello,
Thank you for the detailed bug report. Can you please provide me your platform (OS) and architecture (CPU)? I see you're using musl. Did you compile Wasmer with LIBC=musl?
Hello,
Thank you for the detailed bug report. Can you please provide me your platform (OS) and architecture (CPU)? I see you're using musl. Did you compile Wasmer with
LIBC=musl?
Do you consider providing users with a universal container environment so that everyone can reproduce the problem? @Hywan