GOARCH
当设置为arm64
(或省略)时,我的应用程序编译良好。但是,当我尝试编译 amd64 二进制文件 ( GOOS=darwin GOARCH=amd64 go build
) 时,我收到以下错误:
package [mainPackage]
imports [internalPackageThatUsesC]: build constraints exclude all Go files in [pathToInternalPackageThatUsesC]
[internalPackageThatUsesC]
由 3 个文件组成——一个带有实现的 Objective C 文件、一个头文件和一个为本地代码提供接口的 Go 文件。以下是 Go 文件:
// +build darwin
package [internalPackageThatUsesC]
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#include <Cocoa/Cocoa.h>
#include "[headerFile].h"
*/
import "C"
import (
"encoding/json"
"sync"
"unsafe"
)
... public functions that use the C library to interact with the native code
带有注释的名称[]
意味着它们是实际名称的占位符。
我试图运行它,arch -x86_64
但输出是相同的。
这里有什么问题?我需要添加另一个构建标签吗?
PS 我在 StackOverflow 上发现了关于这个错误的问题,但没有一个是关于为 amd64 编译的。这个问题是最接近的,但它是特定于 WebAssembly 的。
以下是结果go env
:
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/fperson/Library/Caches/go-build"
GOENV="/Users/fperson/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/fperson/.asdf/installs/golang/1.16.4/packages/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/fperson/.asdf/installs/golang/1.16.4/packages"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/fperson/.asdf/installs/golang/1.16.4/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/fperson/.asdf/installs/golang/1.16.4/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/fperson/workspace/personal_projects/timeow/timeow-mac/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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/mh/02gmkb756x15018g919jcg980000gn/T/go-build4031963624=/tmp/go-build -gno-record-gcc-switches -fno-common"