Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CGO seems to force x86 on Apple Silicon #46724

Closed
TimMcL opened this issue Jun 13, 2021 · 3 comments
Closed

CGO seems to force x86 on Apple Silicon #46724

TimMcL opened this issue Jun 13, 2021 · 3 comments

Comments

@TimMcL
Copy link

TimMcL commented Jun 13, 2021

What version of Go are you using (go version)?

$ go version

go version go1.16.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/redacted/Library/Caches/go-build"
GOENV="/Users/redacted/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/redacted/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/redacted/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/redacted/Documents/Programming/GalleryGen/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/84/y_s85tgn5hz55vcw6sc8bth40000gn/T/go-build3915354701=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

$ go build -v -o gallerygen.go
github.com/zidizei/iptc
# github.com/zidizei/iptc
ld: warning: ignoring file /usr/local/lib/libiptcdata.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
  "_iptc_data_new_from_jpeg", referenced from:
      __cgo_61b308e4f4aa_Cfunc_iptc_data_new_from_jpeg in _x002.o
     (maybe you meant: __cgo_61b308e4f4aa_Cfunc_iptc_data_new_from_jpeg)
  "_iptc_data_unref", referenced from:
      __cgo_61b308e4f4aa_Cfunc_iptc_data_unref in _x002.o
     (maybe you meant: __cgo_61b308e4f4aa_Cfunc_iptc_data_unref)
  "_iptc_dataset_get_as_str", referenced from:
      __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_as_str in _x002.o
     (maybe you meant: __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_as_str)
  "_iptc_dataset_get_data", referenced from:
      __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_data in _x002.o
     (maybe you meant: __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_data)
  "_iptc_dataset_get_format", referenced from:
      __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_format in _x002.o
     (maybe you meant: __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_format)
  "_iptc_dataset_get_value", referenced from:
      __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_value in _x002.o
     (maybe you meant: __cgo_61b308e4f4aa_Cfunc_iptc_dataset_get_value)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What did you expect to see?

GOGCCFLAGS using arm64 architecture and then an arm64 compiled executable created.

What did you see instead?

An error message indicating an architecture mismatch between an arm64 library and the current target architecture.

@TimMcL
Copy link
Author

TimMcL commented Jun 13, 2021

I am realizing that it's saying amd64 for architecture not arm64 which I think is what it should say on Apple Silicon, so I think I need to investigate that...

@TimMcL
Copy link
Author

TimMcL commented Jun 13, 2021

It seems the arm64 link actually downloads amd64 so maybe that’s what’s going on here? I can’t seem to figure out how to get the arm64 package.

@TimMcL
Copy link
Author

TimMcL commented Jun 13, 2021

Okay, so I just tried the arm64 link again and this time it actually downloaded the arm64 installer and I confirmed with go version that I have the arm version:

$ go version
go version go1.16.5 darwin/arm64

Now, my code compiles as expected and using the arm64 architecture. I’m not sure why github kept sending me the arm64 installer and what made it finally change its mind, but I have everything working now. To anyone else having this issue: remember arm64 looks a lot like amd64 and make sure you’ve actually downloaded the arm64 installer even if you clicked the amd64 link.

@TimMcL TimMcL closed this as completed Jun 13, 2021
@golang golang locked and limited conversation to collaborators Jun 13, 2022
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

2 participants