gographics / imagick

Go binding to ImageMagick's MagickWand C API
https://godoc.org/github.com/gographics/imagick/imagick
Other
1.77k stars 184 forks source link

Is there support for Apple Silicon M1? #279

Closed pepehandsjpg closed 2 years ago

pepehandsjpg commented 2 years ago

Hi, I tried to research my problem but haven't found any information. I can't figure out how to setup imagick for my 20s Air M1, getting a bunch of errors from ide. Example of an error after installing imagick v3 / v2:

[{
    "resource": "/Users/grdthh/go/pkg/mod/gopkg.in/gographics/imagick.v3@v3.4.1/imagick/affine_matrix.go",
    "owner": "go-staticcheck",
    "severity": 4,
    "message": "could not import C (cgo preprocessing failed) (compile)",
    "source": "go-staticcheck",
    "startLineNumber": 10,
    "startColumn": 8,
    "endLineNumber": 10,
    "endColumn": 9
}]

I tried several potential solutions I found, but each of them leads to different problems, so it would be cool to get a step by step guide on how to install it correctly.

justinfx commented 2 years ago

I've recently gotten access to an Apple M1 laptop so I can test this later. But in the meantime, is it not related to the issue listed in the README on macos where you may need to whitelist cgo flags?

export CGO_CFLAGS_ALLOW='-Xpreprocessor'

I can't speak to how to configure your IDE but you should start by testing the solution from a shell. If you can get that working then it's an IDE specific problem to get the tooling to pick up environment variables.

pepehandsjpg commented 2 years ago

damn, don't know how, but now it works... Apparently while I tried potential solutions i messed up something Anyway thanks a lot! Feeling stupid...

justinfx commented 2 years ago

That's ok. Thanks for confirming. Just means we don't need to do any investigation 😊

lesnoyleshyi commented 2 years ago

Hi! According to my google skills, I faced an M1-relative problem. I get an error from linker when try to compile:

/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /opt/homebrew/Cellar/imagemagick/7.1.0-48/lib/libMagickWand-7.Q16HDRI.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/imagemagick/7.1.0-48/lib/libMagickCore-7.Q16HDRI.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_AcquireDrawInfo", referenced from:
      __cgo_83eb6e58db04_Cfunc_AcquireDrawInfo in 000016.o
     (maybe you meant: __cgo_83eb6e58db04_Cfunc_AcquireDrawInfo)
...
etc

Could you help me please?

justinfx commented 2 years ago

@lesnoyleshyi

/usr/local/go/pkg/tool/darwin_amd64/link

That means you have installed a version of Go that was built for amd64. But the M1 architecture is arm64. So it fails when you try to build your Go code and then link against C ImageMagick that was built for arm64. You should uninstall Go, and download and reinstall the arm64 version.

Another option is to try setting your env with export GOARCH=arm64. This may or may not work.