gpt4 book ai didi

gomobile init 找不到 stdlib.h

转载 作者:IT王子 更新时间:2023-10-29 01:47:17 25 4
gpt4 key购买 nike

我正在尝试使用 go 创建一个跨平台的 native 库并找到 this gomobile教程。但是,当我尝试初始化它时(即使我在下面的示例中没有提供 Android NDK 路径)它似乎失败了,因为它找不到 stdlib.h

我尝试围绕 cgo 进行一些调查,但没有任何结果,希望更熟悉生态系统的人能为我指明正确的方向。

$ gomobile init
gomobile: go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm std failed: exit status 2
# runtime/cgo
_cgo_export.c:2:10: fatal error: 'stdlib.h' file not found

我的环境...(我在 OS X El Capitan 上,全新安装了 go1.9 darwin/amd64)

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/myusername/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rx/l7pzlrld2mqczrfb36t536hh0000gp/T/go-build735124167=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

编辑:(添加失败初始化的详细输出)

$ gomobile init -v# Installing golang.org/x/mobile/gl.# Installing golang.org/x/mobile/app.# Installing golang.org/x/mobile/exp/app/debug.# Installing std for android/arm.runtime/internal/sysruntime/internal/atomicruntimesync/atomicunicodeinternal/raceerrorsunicode/utf8mathmath/bitscontainer/listcontainer/ringcrypto/subtlecrypto/internal/cipherhwinternal/nettraceruntime/cgovendor/golang_org/x/crypto/poly1305syncencodingunicode/utf16image/colorinternal/cpuinternal/syscall/windowsinternal/syscall/windows/registryimage/color/paletteinternal/syscall/windows/sysdlliosyscallinternal/singleflightruntime/race# runtime/cgo_cgo_export.c:2:10: fatal error: 'stdlib.h' file not foundvendor/golang_org/x/text/securevendor/golang_org/x/text/unicodebytesstringshashcrypto/cipherruntime/tracehash/crc32hash/adler32crypto/hmachash/crc64hash/fnvvendor/golang_org/x/text/transformtext/tabwriterbufiopathhtmlstrconvmath/randmath/cmplxtimeinternal/syscall/unixreflectcrypto/aescryptocrypto/rc4encoding/base64encoding/base32encoding/ascii85crypto/sha512crypto/md5crypto/sha1crypto/sha256imageinternal/pollimage/internal/imageutilimage/drawimage/jpegosos/signalfmtsortencoding/binarypath/filepathcompress/bzip2encoding/pemcontainer/heapregexp/syntaxruntime/debugcrypto/desvendor/golang_org/x/crypto/chacha20poly1305/internal/chacha20vendor/golang_org/x/crypto/curve25519vendor/golang_org/x/crypto/chacha20poly1305io/ioutilcompress/flatecontextarchive/tarmath/bigcompress/lzwencoding/hexdebug/dwarfdebug/gosymdebug/plan9objdatabase/sql/driverencoding/csvencoding/gobencoding/jsondatabase/sqlencoding/xmlarchive/zipcompress/gzipcompress/zlibdebug/machodebug/elfdebug/pelogvendor/golang_org/x/net/http2/hpackvendor/golang_org/x/text/unicode/bidivendor/golang_org/x/text/unicode/normnet/urlmimemime/quotedprintablenet/http/internalflagcrypto/dsacrypto/ellipticencoding/asn1crypto/randgo/tokengo/scannercrypto/rsavendor/golang_org/x/text/secure/bidiruleregexptext/template/parsego/astgo/constantos/exectext/scannercrypto/ecdsacrypto/x509/pkiximage/gifimage/pngvendor/golang_org/x/net/idnaindex/suffixarraytestinginternal/traceruntime/pproftext/templatenet/internal/socktestos/userruntime/pprof/internal/profiletesting/iotesttesting/quickgo/parsergo/printertesting/internal/testdepsinternal/testenvgo/dochtml/templatego/typesgo/formatgo/buildgo/internal/gccgoimportergo/internal/gcimportergo/internal/srcimportergo/importergomobile: go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm -v std failed: exit status 2

最佳答案

即使使用 issue21802,问题仍然在 go1.10 darwin/amd64 上重现已打补丁。

如果 go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm std 可以自己运行它成功问题是运行时 ENV 问题,有解决方法。

解决这个问题的技巧:

1.手动运行 go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm std确保安装成功

2.然后在init.go中静默installStd

go/src/golang.org/x/mobile/cmd/gomobile/init.go (around Line 165-175)
// Install standard libraries for cross compilers.
start := time.Now()
//if ndkRoot != "" {
// Ideally this would be -buildmode=c-shared.
// https://golang.org/issue/13234.
// androidArgs := []string{"-gcflags=-shared", "-ldflags=-shared"}
// for _, arch := range archs {
// env := androidEnv[arch]
// if err := installStd(env, androidArgs...); err != nil {
// return err
// }
// }
//}

3.再次安装解决方法gomobile:go install golang.org/x/mobile/cmd/gomobile

4.再次运行gomobile init

关于gomobile init 找不到 stdlib.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com