gomobile init找不到stdlib.h

时间:2017-09-07 19:07:45

标签: go gomobile

我正在尝试使用go找到一个跨平台的本地库,并找到了gomobile的this教程。但是,当我尝试初始化它时(即使我在下面的示例中没有提供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/sys
runtime/internal/atomic
runtime
sync/atomic
unicode
internal/race
errors
unicode/utf8
math
math/bits
container/list
container/ring
crypto/subtle
crypto/internal/cipherhw
internal/nettrace
runtime/cgo
vendor/golang_org/x/crypto/poly1305
sync
encoding
unicode/utf16
image/color
internal/cpu
internal/syscall/windows
internal/syscall/windows/registry
image/color/palette
internal/syscall/windows/sysdll
io
syscall
internal/singleflight
runtime/race
# runtime/cgo
_cgo_export.c:2:10: fatal error: 'stdlib.h' file not found
vendor/golang_org/x/text/secure
vendor/golang_org/x/text/unicode
bytes
strings
hash
crypto/cipher
runtime/trace
hash/crc32
hash/adler32
crypto/hmac
hash/crc64
hash/fnv
vendor/golang_org/x/text/transform
text/tabwriter
bufio
path
html
strconv
math/rand
math/cmplx
time
internal/syscall/unix
reflect
crypto/aes
crypto
crypto/rc4
encoding/base64
encoding/base32
encoding/ascii85
crypto/sha512
crypto/md5
crypto/sha1
crypto/sha256
image
internal/poll
image/internal/imageutil
image/draw
image/jpeg
os
os/signal
fmt
sort
encoding/binary
path/filepath
compress/bzip2
encoding/pem
container/heap
regexp/syntax
runtime/debug
crypto/des
vendor/golang_org/x/crypto/chacha20poly1305/internal/chacha20
vendor/golang_org/x/crypto/curve25519
vendor/golang_org/x/crypto/chacha20poly1305
io/ioutil
compress/flate
context
archive/tar
math/big
compress/lzw
encoding/hex
debug/dwarf
debug/gosym
debug/plan9obj
database/sql/driver
encoding/csv
encoding/gob
encoding/json
database/sql
encoding/xml
archive/zip
compress/gzip
compress/zlib
debug/macho
debug/elf
debug/pe
log
vendor/golang_org/x/net/http2/hpack
vendor/golang_org/x/text/unicode/bidi
vendor/golang_org/x/text/unicode/norm
net/url
mime
mime/quotedprintable
net/http/internal
flag
crypto/dsa
crypto/elliptic
encoding/asn1
crypto/rand
go/token
go/scanner
crypto/rsa
vendor/golang_org/x/text/secure/bidirule
regexp
text/template/parse
go/ast
go/constant
os/exec
text/scanner
crypto/ecdsa
crypto/x509/pkix
image/gif
image/png
vendor/golang_org/x/net/idna
index/suffixarray
testing
internal/trace
runtime/pprof
text/template
net/internal/socktest
os/user
runtime/pprof/internal/profile
testing/iotest
testing/quick
go/parser
go/printer
testing/internal/testdeps
internal/testenv
go/doc
html/template
go/types
go/format
go/build
go/internal/gccgoimporter
go/internal/gcimporter
go/internal/srcimporter
go/importer
gomobile: go install -gcflags=-shared -ldflags=-shared -pkgdir=/Users/myusername/go/pkg/gomobile/pkg_android_arm -v std failed: exit status 2

1 个答案:

答案 0 :(得分:0)

即使修补了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.然后在installStd内静默init.go

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.再次安装解决方法:go install golang.org/x/mobile/cmd/gomobile

4.再次运行gomobile init

相关问题