gen2brain / go-fitz

Golang wrapper for the MuPDF Fitz library
GNU Affero General Public License v3.0
369 stars 87 forks source link

linux ubuntu build fail #91

Closed foobarhe closed 10 months ago

foobarhe commented 10 months ago

I googled sigsetjmp, but failed find anything useful, could you please help?

CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags musl -o bin/zapp_process main.go  

# github.com/gen2brain/go-fitz
/usr/bin/ld: /root/go/pkg/mod/github.com/gen2brain/go-fitz@v1.22.2/libs/libmupdf_linux_amd64_musl.a(buffer.o): in function `fz_new_buffer':
buffer.c:(.text.fz_new_buffer+0x47): undefined reference to `sigsetjmp'
/usr/bin/ld: /root/go/pkg/mod/github.com/gen2brain/go-fitz@v1.22.2/libs/libmupdf_linux_amd64_musl.a(buffer.o): in function `fz_new_buffer_from_data':
buffer.c:(.text.fz_new_buffer_from_data+0x27): undefined reference to `sigsetjmp'
/usr/bin/ld: /root/go/pkg/mod/github.com/gen2brain/go-fitz@v1.22.2/libs/libmupdf_linux_amd64_musl.a(buffer.o): in function `fz_new_buffer_from_base64':
buffer.c:(.text.fz_new_buffer_from_base64+0xeb): undefined reference to `sigsetjmp'
/usr/bin/ld: /root/go/pkg/mod/github.com/gen2brain/go-fitz@v1.22.2/libs/libmupdf_linux_amd64_musl.a(colorspace.o): in function `fz_cached_color_convert':
colorspace.c:(.text.fz_cached_color_convert+0x9f): undefined reference to `sigsetjmp'
/usr/bin/ld: /root/go/pkg/mod/github.com/gen2brain/go-fitz@v1.22.2/libs/libmupdf_linux_amd64_musl.a(colorspace.o): in function `fz_new_colorspace':
colorspace.c:(.text.fz_new_colorspace+0x6f): undefined reference to `sigsetjmp'
/usr/bin/ld: /root/go/pkg/mod/github.com/gen2brain/go-fitz@v1.22.2/libs/libmupdf_linux_amd64_musl.a(colorspace.o):colorspace.c:(.text.fz_new_icc_colorspace+0x76): more undefined references to `sigsetjmp' follow
collect2: error: ld returned 1 exit status
gen2brain commented 10 months ago

You cannot build for musl target and use your system glibc toolchain and gcc, remove -tags musl.

gen2brain commented 10 months ago

Or, you can install musl toolchain and use gcc from musl, i.e. add something like this CC=x86_64-pc-linux-musl-gcc to your build line.

xiaohongred commented 10 months ago

in macos , i use: GOOS=linux GOARCH=amd64 go build -o myTarget have err: undefined: fitz.NewFromMemory

what should i do to solve this problem

gen2brain commented 10 months ago

When you cross-compile, Go by default disables CGO, enable it with CGO_ENABLED=1. Then you will probably get different errors from the compiler, you cannot just change GOOS and GOARCH. The rules are the same as when you cross-compile a C project, you must pass CC and use the appropriate toolchain. That has nothing to do specifically with this but with every CGO project. To solve this use the appropriate compiler in CC, i.e. zig cc -target x86_64-linux-gnu, maybe clang --target x86_64-pc-linux-gnu can be used, etc.

xiaohongred commented 10 months ago

Thank you very much for your reply