ziglang / zig

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

Unable to compile gen2brain/go-fitz library with GOOS and GOARCH #12166

Open anandsoni11 opened 2 years ago

anandsoni11 commented 2 years ago

Hi, I am using zig to cross compile a go module (go-fitz) on my Mac. The compiler options used are as below :

GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC="zig cc -target x86_64-linux" CXX="zig c++ -target x86_64-linux" go build -o main *.go

But, I am getting the below error on compilation -

/usr/local/Cellar/go/1.18/libexec/pkg/tool/darwin_amd64/link: running zig failed: exit status 1
ld.lld: error: undefined symbol: __fprintf_chk
>>> referenced by context.c
>>>               context.o:(fz_new_context_imp) in archive /Users/user1/go/pkg/mod/github.com/gen2brain/go-fitz@v1.18.0/libs/libmupdf_linux_amd64.a
>>> referenced by error.c
>>>               error.o:(fz_default_error_callback) in archive /Users/user1/go/pkg/mod/github.com/gen2brain/go-fitz@v1.18.0/libs/libmupdf_linux_amd64.a
>>> referenced by error.c
>>>               error.o:(fz_default_warning_callback) in archive /Users/user1/go/pkg/mod/github.com/gen2brain/go-fitz@v1.18.0/libs/libmupdf_linux_amd64.a
>>> referenced 39 more times

On the other hand, if I use the below options, the compilation runs successfully but I get a segmentation fault at runtime : GOOS=linux GOARCH=amd64 CGO_ENABLED=1 CC="zig cc -target x86_64-linux-gnu" go build -o main *.go Can you please help me here? Thank you!

kassane commented 2 years ago

Have you tried adding the flag -lc on cc and -lc++ on cxx?

danvergara commented 2 months ago

Any solution yet? Ran into this yesterday