Closed charliecen closed 1 year ago
Am I reading this correctly? You are trying to cross compile from your macos to a Linux target using the musl compiler built and installed on macos and get it to link against an ImageMagick that was built for macos and not Linux?
Am I reading this correctly? You are trying to cross compile from your macos to a Linux target using the musl compiler built and installed on macos and get it to link against an ImageMagick that was built for macos and not Linux?
yes
Wouldn't you need to have an ImageMagick7 that you have also compiled with musl, for the same linux target? And then you might be able to point your Go build to link against the Linux ImageMagick. But it isn't likely going to work to try to link against your macos ImageMagick. Also, if you go with musl, everything needs to be compiled with musl and it needs to run under a musl distro.
It is possible to compile golang project on alpine linux.
Yes, I know it is possible to compile a Go project on alpine linux. What I am pointing out though is not only do you want to compile your Golang project on Alpine Linux, but you also want to compile a cgo project that needs to link against a C library called ImageMagick. If you want to do that, you will also need to have ImageMagick compiled for linux, using the musl compiler.
You might find it easier to just use Docker. You can see an older example that we use to build a specific version of ImageMagick and the compile, link, and run the tests: https://github.com/gographics/imagick/blob/im-7/Dockerfile
Now if you really want to use Alpine, you could switch to using an alpine image and install ImageMagick and the compiler tools:
FROM golang:1.20-alpine
RUN apk add g++ gcc imagemagick-dev
WORKDIR /src
CMD go build .
Here is a more complete example, using alpine:
Dockerfile
FROM golang:1.20-alpine
RUN apk add g++ gcc imagemagick-dev
WORKDIR /src
CMD go build .
Now make an image
docker build -t imagick_builder:latest .
Jump into your project, and build it:
cd my_project
docker run --rm -v $PWD:/src imagick_builder:latest
It should mount your current source dir into the container, build it with musl and ImageMagick under linux and write your binary to the same dir
ok, thinks
I use command build go project error
my os
go version
magic version