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

cmd/cgo: failed to run c-archive library built for iOS #41177

Open
rogchap opened this issue Sep 2, 2020 · 3 comments
Open

cmd/cgo: failed to run c-archive library built for iOS #41177

rogchap opened this issue Sep 2, 2020 · 3 comments

Comments

@rogchap
Copy link

@rogchap rogchap commented Sep 2, 2020

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

$ go version
go version go1.15.1 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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/roger/Library/Caches/go-build"
GOENV="/Users/roger/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/roger/go/pkg/mod"
GONOPROXY="github.com/XXXXXX"
GONOSUMDB="github.com/XXXXXX"
GOOS="darwin"
GOPATH="/Users/roger/go"
GOPRIVATE="github.com/XXXXXXX"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/roger/Development/XXXXX/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 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/y8/8fn4c6b54y38lyvqcmsxk9hc0000gn/T/go-build298028240=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Create a simple go program that has C export function:

package main

import "C"

//export sayHello
func sayHello() string {
	return "Hello from Go\x00"
}

func main() {}

build the code with the following:

CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 CC=$(shell go env GOROOT)/misc/ios/clangwrap.sh CGO_CFLAGS="-fembed-bitcode" go build -buildmode=c-archive -tags ios -o arm64.a .

Build is successful.

Add the arm64.a and arm64.h to an iOS project in XCode, and add #import "arm64.h" to the bridging header file.

Call the sayHello function from Swift:

let hello = sayHello()
self.helloLabel = String.init(cString: hello.p, encoding: .utf8)!

What did you expect to see?

XCode to build successfully, and the helloLabel to be updated with "Hello from Go".

What did you see instead?

I get a very strange error from XCode that states iOS-arm64 != iOS-arm64!:

ignoring file /Users/roger/Development/XXXXX/arm64.a, building for iOS-arm64 but attempting to link with file built for iOS-arm64
$ lipo -info arm64.a
Non-fat file: arm64.a is architecture: arm64

Ps. I previously had this working successfully, but I can't see what changed other than upgrading to Go 1.15 (I tried downgrading to 1.14.6 but no change) and updating Catalina to 10.15.6

@cherrymui
Copy link
Contributor

@cherrymui cherrymui commented Sep 2, 2020

(I tried downgrading to 1.14.6 but no change)

Could you clarify what is "no change"? It still doesn't work after downgrading, or it goes back to work? Thanks.

That error message is indeed mysterious...

@rogchap
Copy link
Author

@rogchap rogchap commented Sep 2, 2020

Does not work after downgrade; same error with 1.14.6

@dmitshur dmitshur added this to the Backlog milestone Sep 3, 2020
@rogchap
Copy link
Author

@rogchap rogchap commented Sep 14, 2020

Seems to be an environment issue that I have yet to track down. I've been able to take the same code and build successfully on another machine; copy the library to the failing machine and now XCode builds successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.