Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on compiling go source with CGO_ENABLED=1 #22118

Closed
angeloc opened this issue Oct 3, 2017 · 3 comments
Closed

Error on compiling go source with CGO_ENABLED=1 #22118

angeloc opened this issue Oct 3, 2017 · 3 comments

Comments

@angeloc
Copy link

angeloc commented Oct 3, 2017

What version of Go are you using (go version)?

Go 1.8.3 (but 1.9 exhibits same behavior).

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

I'm compili go source code inside buildroot on host machine X86_64 versus a target architecture ARM.

What did you do?

I compile go with this command:

cd /media/angelo/WD/data/BUILDROOT/br_qemu_arm/build/host-go-1.8.3/src && GOROOT_BOOTSTRAP=/media/angelo/WD/data/BUILDROOT/br_qemu_arm/host/lib/go-1.4.3 GOROOT_FINAL=/media/angelo/WD/data/BUILDROOT/br_qemu_arm/host/lib/go GOROOT="/media/angelo/WD/data/BUILDROOT/br_qemu_arm/build/host-go-1.8.3" GOBIN="/media/angelo/WD/data/BUILDROOT/br_qemu_arm/build/host-go-1.8.3/bin" GOARCH=arm GOARM=5 GOOS=linux CGO_ENABLED=1 CC=/usr/bin/gcc CC_FOR_TARGET=/usr/bin/gcc CXX_FOR_TARGET=/usr/bin/gcc ./make.bash

What did you expect to see?

The go executable and companion software compiled correctly.

What did you see instead?

[...]
##### Building packages and commands for linux/arm.
runtime/internal/sys
runtime/internal/atomic
runtime
errors
internal/race
sync/atomic
unicode
unicode/utf8
math
container/list
container/ring
crypto/subtle
crypto/internal/cipherhw
internal/nettrace
runtime/cgo
vendor/golang_org/x/crypto/curve25519
encoding
sync
unicode/utf16
# runtime/cgo
gcc: error: unrecognized command line option '-marm'
image/color
vendor/golang_org/x/crypto/poly1305
internal/syscall/windows
internal/syscall/windows/registry
internal/syscall/windows/sysdll
runtime/race
cmd/compile/internal/test
cmd/vet/internal/whitelist
syscall
io
internal/singleflight
image/color/palette
hash
crypto/cipher
runtime/trace
bytes
strings
hash/adler32
hash/crc32
crypto/hmac
hash/crc64
hash/fnv
strconv
math/rand
math/cmplx
bufio
text/tabwriter
vendor/golang_org/x/text/transform
path
html
reflect
crypto
crypto/aes
crypto/rc4
encoding/base64
encoding/ascii85
encoding/base32
crypto/sha512
crypto/md5
crypto/sha1
crypto/sha256
image
internal/syscall/unix
time
image/internal/imageutil
image/draw
image/jpeg
os
os/signal
fmt
encoding/binary
sort
regexp/syntax
path/filepath
compress/bzip2
container/heap
encoding/pem
runtime/debug
cmd/internal/sys
crypto/des
vendor/golang_org/x/crypto/chacha20poly1305/internal/chacha20
vendor/golang_org/x/crypto/chacha20poly1305
io/ioutil
cmd/internal/dwarf
flag
log
debug/dwarf
compress/flate
debug/gosym
debug/plan9obj
cmd/vendor/golang.org/x/arch/arm/armasm
cmd/vendor/golang.org/x/arch/ppc64/ppc64asm
cmd/vendor/golang.org/x/arch/x86/x86asm
regexp
cmd/internal/obj
archive/tar
compress/zlib
archive/zip
compress/gzip
compress/lzw
context
math/big
debug/elf
debug/macho
debug/pe
encoding/hex
database/sql/driver
encoding/csv
encoding/gob
cmd/internal/goobj
encoding/json
encoding/xml
database/sql
vendor/golang_org/x/net/http2/hpack
vendor/golang_org/x/net/idna
vendor/golang_org/x/text/unicode/norm
cmd/internal/objfile
vendor/golang_org/x/text/width
crypto/dsa
crypto/elliptic
encoding/asn1
cmd/addr2line
crypto/rand
mime
mime/quotedprintable
crypto/rsa
crypto/ecdsa
crypto/x509/pkix
net/http/internal
net/url
go/token
text/template/parse
os/exec
text/scanner
image/gif
go/scanner
go/constant
image/png
index/suffixarray
internal/pprof/profile
testing
internal/trace
go/ast
net/internal/socktest
testing/iotest
testing/quick
text/template
cmd/internal/obj/arm
cmd/internal/obj/arm64
cmd/internal/obj/mips
cmd/internal/obj/ppc64
internal/testenv
cmd/internal/obj/s390x
go/parser
go/printer
runtime/pprof/internal/protopprof
cmd/internal/obj/x86
runtime/pprof
go/doc
html/template
testing/internal/testdeps
cmd/asm/internal/flags
go/types
cmd/asm/internal/lex
go/format
cmd/internal/bio
go/build
cmd/cgo
cmd/compile/internal/syntax
cmd/internal/gcprog
cmd/internal/browser
cmd/dist
cmd/fix
cmd/gofmt
cmd/asm/internal/arch
cmd/compile/internal/ssa
cmd/asm/internal/asm
cmd/cover
cmd/doc
cmd/link/internal/ld
cmd/asm
cmd/nm
cmd/objdump
cmd/pack
cmd/pprof/internal/plugin
go/internal/gccgoimporter
go/internal/gcimporter
cmd/api
cmd/pprof/internal/report
cmd/pprof/internal/svg
cmd/pprof/internal/tempfile
cmd/pprof/internal/symbolizer
go/importer
cmd/pprof/internal/symbolz
cmd/vet/internal/cfg
cmd/vet
cmd/pprof/internal/commands
cmd/pprof/internal/driver
cmd/link/internal/arm
cmd/link/internal/arm64
cmd/link/internal/amd64
cmd/link/internal/mips
cmd/link/internal/mips64
cmd/link/internal/ppc64
cmd/link/internal/s390x
cmd/link/internal/x86
cmd/link
cmd/compile/internal/gc
cmd/compile/internal/amd64
cmd/compile/internal/arm
cmd/compile/internal/arm64
cmd/compile/internal/mips
cmd/compile/internal/mips64
cmd/compile/internal/ppc64
cmd/compile/internal/s390x
cmd/compile/internal/x86
cmd/compile
package/pkg-generic.mk:234: recipe for target '/media/angelo/WD/data/BUILDROOT/br_qemu_arm/build/host-go-1.8.3/.stamp_built' failed
make[1]: *** [/media/angelo/WD/data/BUILDROOT/br_qemu_arm/build/host-go-1.8.3/.stamp_built] Error 2

There's an error somewhere, but I cannot find it simply looking at the build output. Can you provide some advice to debug this problem and eventually helping to fix it and submit (if submittable)?

Thanks!

@davecheney
Copy link
Contributor

davecheney commented Oct 3, 2017 via email

@angeloc
Copy link
Author

angeloc commented Oct 3, 2017

Thanks for the reply @davecheney .

In buildroot we have the need to build packages for a target architecture that can be different from the host one. So we are trying to compile a go compiler that will produce go binaries for the target architecture.
I actually had a suspect something was not working like expected when I had the error "no buildable Go source files in ..." and I noticed that the go files were all files whit embedded C and in need of cgo.

So I thought that something was wrong with the compilation of the go binary and tools and noticed that CGO_ENABLED was set to 0.

So in the end, to crosscompile a package with embedded C should I use CGO for the target architecture or am I wrong?

@ianlancetaylor
Copy link
Member

In order to build a Go cross-compiler with cgo enabled, you need to provide C cross-compilers to your target. You set CC_FOR_TARGET to /usr/bin/gcc, but that is very unlikely to be a cross-compiler. You need a compiler that runs on your x86_64 host and generates code for ARM.

Closing this issue because I don't see anything to fix in Go. For further questions please use a forum; see https://golang.org/wiki/Questions. Thanks.

@golang golang locked and limited conversation to collaborators Oct 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants