Skip to content

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

Open
@rogchap

Description

@rogchap

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.mobileAndroid, iOS, and x/mobile

    Type

    No type

    Projects

    Status

    Triage Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions