Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

mac m1 can not run cgo #45772

Closed
benggee opened this issue Apr 26, 2021 · 6 comments
Closed

mac m1 can not run cgo #45772

benggee opened this issue Apr 26, 2021 · 6 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@benggee
Copy link

benggee commented Apr 26, 2021

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

$ go version
go version go1.16.3 darwin/arm64
go env Output
$ go env
GO111MODULE="on"
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/xxx/Library/Caches/go-build"
GOENV="/Users/xxx/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mrbinary/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ny/w9t1brsx7hq3gjc0tlfy6yyc0000gn/T/go-build2251407779=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Undefined symbols for architecture arm64:
"_create_byte_array", referenced from:
__cgo_21bc20011f30_Cfunc_create_byte_array in _x002.o
(maybe you meant: __cgo_21bc20011f30_Cfunc_create_byte_array)
"_decrypt", referenced from:
__cgo_21bc20011f30_Cfunc_decrypt in _x002.o
(maybe you meant: __cgo_21bc20011f30_Cfunc_decrypt)
"_get_key", referenced from:
__cgo_21bc20011f30_C2func_get_key in _x002.o
__cgo_21bc20011f30_Cfunc_get_key in _x002.o
(maybe you meant: __cgo_21bc20011f30_Cfunc_get_key, __cgo_21bc20011f30_C2func_get_key )
"_release_byte_array", referenced from:
__cgo_21bc20011f30_Cfunc_release_byte_array in _x002.o
(maybe you meant: __cgo_21bc20011f30_Cfunc_release_byte_array)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@cherrymui
Copy link
Member

The darwin/arm64 port supports cgo. Could you provide the instruction to reproduce this, including the program you are building? Thanks.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Apr 26, 2021
@benggee
Copy link
Author

benggee commented Apr 28, 2021

The environment variable of my IDE is like this:
GOARCH=arm64;GOOS=darwin

My version of the clang compiler like this:
Target: arm64-apple-darwin20.2.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

@cherrymui
Copy link
Member

What IDE is it? Do you know what commands does it run when you build your program? Could you capture the full error message? And what is the program source code? Thanks.

@ChristianOrgler
Copy link

Similar issue,

same env variables, clang compiler:
Apple clang version 13.0.0 (clang-1300.0.18.6) Target: arm64-apple-darwin20.5.0 Thread model: posix InstalledDir: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I'm trying to build wireguard's go kit and it misses symbols for arm64 in runtime/cgo:

go build -ldflags=-w -trimpath -v -o "/Users/someone/Library/Developer/Xcode/DerivedData/something-bipqhwawbdbbciblevyubvleyofz/Build/Intermediates.noindex/something.build/Debug-iphonesimulator/wireguard-go-bridge/libwg-go-arm64.a" -buildmode c-archive

runtime/cgo
# runtime/cgo

Undefined symbols for architecture arm64:
  "_darwin_arm_init_mach_exception_handler", referenced from:
      _x_cgo_init in _x004.o

  "_darwin_arm_init_thread_exception_port", referenced from:
      _threadentry in _x004.o
      _x_cgo_init in _x004.o

ld: symbol(s) not found for architecture arm64


@cherrymui
Copy link
Member

@ChristianOrgler are you building for macOS or iOS?

The references of those two functions should only appear if TARGET_OS_IPHONE is #defined.

Could you share your environment when running the go build? Thanks.

@ChristianOrgler
Copy link

I'm building for iOS - yet I figured out that the culprit is with the Makefile of the vendor not GO in particular.

@golang golang locked and limited conversation to collaborators Dec 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants