Cgo build error, help me!


(Bill Anderson) #1

I met a problem
I compiled a native ELF binary running on android arm7 on Ubuntu.

Export GOOS=android
Export GOARCH=arm
Export GOARM=7
Export CGO_ENABLED=1

Export CGO_CFLAGS="-g -O2 --sysroot=/mnt/d/sdk/android/android-ndk-r14b-linux/android-24/arch-arm"
Export CGO_LDFLAGS="–sysroot=/mnt/d/sdk/android/android-ndk-r14b-linux/android-24/arch-arm"
Export CC=arm-linux-androideabi-gcc
Export CC_FOR_TARGET=arm-linux-androideabi-gcc
Export CXX=arm-linux-androideabi-g++

runtime/cgo

_cgo_export.c:3:20: fatal error: stdlib.h: No such file or directory
#include <stdlib.h>

How can I solve this error?


(Sean Killian) #2

Hi, Bill,

I’ll preface this with the fact that I have no experience with cross-compiling cgo, but are there a specific libc source packages for arm-7 and do you have them installed?

I found a library on GitHub that works with cross compilation of cgo: https://github.com/karalabe/xgo/

Maybe that can help you?


(Bill Anderson) #3

Thank you very much
I have solved this problem.

GO111MODULE=""
GOARCH=“arm”
GOBIN=""
GOCACHE="/home/dev/.cache/go-build"
GOENV="/home/dev/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH=“amd64”
GOHOSTOS=“linux”
GONOPROXY=""
GONOSUMDB=""
GOOS=“android”
GOPATH="/mnt/d/tmp/arm7_android"
GOPRIVATE=""
GOPROXY=“https://proxy.golang.org,direct”
GOROOT="/usr/local/go"
GOSUMDB=“sum.golang.org
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO=“gccgo”
GOARM=“7”
AR=“ar”
CC=“arm-linux-androideabi-gcc”
CXX=“g++”
CGO_ENABLED=“1”
GOMOD=""
CGO_CFLAGS="-g -O2 --sysroot=/mnt/d/sdk/android/android-ndk-r14b-linux/platforms/android-24/arch-arm"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="–sysroot=/mnt/d/sdk/android/android-ndk-r14b-linux/platforms/android-24/arch-arm"
PKG_CONFIG=“pkg-config”
GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build291331330=/tmp/go-build -gno-record-gcc-switches"

config --sysroot path
CC=arm-linux-androideabi-gcc