Open ash2k opened 7 years ago
@forskning
I can cross compile a linux exe with cgo on macOS with go1.9 and gcc 7.2.0.
go version go1.9 darwin/amd64
> /usr/local/x86_64-ubuntu14.04-linux-gnu/bin/x86_64-ubuntu14.04-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/usr/local/x86_64-ubuntu14.04-linux-gnu/bin/x86_64-ubuntu14.04-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/local/x86_64-ubuntu14.04-linux-gnu/bin/../libexec/gcc/x86_64-ubuntu14.04-linux-gnu/7.2.0/lto-wrapper
Target: x86_64-ubuntu14.04-linux-gnu
Configured with: /Volumes/ct-ng/build_dir/crosstool-ng/.build/x86_64-ubuntu14.04-linux-gnu/src/gcc/configure --build=x86_64-build_apple-darwin16.7.0 --host=x86_64-build_apple-darwin16.7.0 --target=x86_64-ubuntu14.04-linux-gnu --prefix=/Volumes/ct-ng/ct-ng/x86_64-ubuntu14.04-linux-gnu --with-sysroot=/Volumes/ct-ng/ct-ng/x86_64-ubuntu14.04-linux-gnu/x86_64-ubuntu14.04-linux-gnu/sysroot --enable-languages=c,c++ --with-pkgversion='crosstool-NG crosstool-ng-1.23.0-220-g2ebbd3e3' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --enable-libmpx --with-gmp=/Volumes/ct-ng/build_dir/crosstool-ng/.build/x86_64-ubuntu14.04-linux-gnu/buildtools --with-mpfr=/Volumes/ct-ng/build_dir/crosstool-ng/.build/x86_64-ubuntu14.04-linux-gnu/buildtools --with-mpc=/Volumes/ct-ng/build_dir/crosstool-ng/.build/x86_64-ubuntu14.04-linux-gnu/buildtools --with-isl=/Volumes/ct-ng/build_dir/crosstool-ng/.build/x86_64-ubuntu14.04-linux-gnu/buildtools --enable-lto --enable-threads=posix --enable-target-optspace --disable-plugin --disable-nls --disable-multilib --with-local-prefix=/Volumes/ct-ng/ct-ng/x86_64-ubuntu14.04-linux-gnu/x86_64-ubuntu14.04-linux-gnu/sysroot --enable-long-long
Thread model: posix
gcc version 7.2.0 (crosstool-NG crosstool-ng-1.23.0-220-g2ebbd3e3)
The 10-10-15 dated comment by T. de Zeeuw in the link I provided seems to indicate a failed attempt to utilise a gcc compiled for darwin, rather than following I.L. Taylor's suggestion in an earlier comment to that issue, to utilise a "Darwin -> GNU/Linux cross-compiler".
https://github.com/golang/go/wiki/WindowsCrossCompiling
Perhaps similar as A. Donizetti's above wiki page it would be of interest to the community to have a "LinuxCrossCompiling" wiki page.
You need to have a cross-compiler.
I guess I'll leave this issue open for documentation.
CC @ALTree
@forskning I'm not really the author of that wikipage, I just happen to be the last person who edited it : )
That said, I agree we could use a {Linux or OsX}CrossCompiling wiki page, since it's something that apparently trips a lot of people and issues about this always end up with someone writing the usual "you need a cross-compiling toolchain to do this." We could write down the procedure nicely once, and then just link the wiki page.
FWIW, possibly https://github.com/golang/go/issues/22041 could also use a HelpWanted label.
Is it possible to just create a golang zip for macos/linux/windows that include a cross compile gcc for macos/linux/windows ? So that people will find that cross compile cgo just work,I do not want to install a lot of stuff to just make cross compile works.Just give me the working binary. I think the zip size is not a problem.The package for unity 3d is more than 5GB.
Why don’t we just make the Go tool refuse to operate if it is in cross compilation mode and cgo is enabled and the host cc options are not set?
On 28 Oct 2017, at 00:48, Alberto Donizetti notifications@github.com wrote:
@forskning I'm not really the author of that wikipage, I just happen to be the last person who edited it : )
That said, I agree we could use {Linux,OsX}CrossCompiling wiki pages, since it's something that apparently trips a lot of people and issues about this always end up with someone writing the usual "you need a cross-compiling toolchain to do this." We could write it down nicely once and then just link the wiki page.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.
https://forum.golangbridge.org/t/go-mobile-commands/7002
There's a recent somewhat lengthy series of topics on golangbridge.org.
Specifically pertaining to the subrepo mobile and external software; an install of Java8, Android Studio, and NDK, where just for the Android Studio/Android SDK there is the minimum requirement of an allocation of 2GB of free harddrive space.
I think its worth noting here the comment of I.L.T. to (the now Abandoned) https://golang.org/cl/69430, inferring that in regards to that proposed change in the golang.org introductory documentation, that installation of a cross-compiler was more intermediate or advanced level coding.
With host cc options not being set and a message output to that effect this might likewise infer that the coder was at an intermediate or advanced level, in order for that coder to interpret the shell message.
https://forum.golangbridge.org/t/cannot-find-package-golang-org-x-tools-cmd-goimports/7000
With all due respect I like S. Binet's comment near the closing of a separate golangbridge.org topic.
"it’s left as an exercize for the reader"
That is, with the documentation available, it's left to the reader to be able to locate that information.
But, I note the drawing of R. French on golang.org/help.
Why don’t we just make the Go tool refuse to operate if it is in cross compilation mode and cgo is enabled and the host cc options are not set?
@davecheney works for me. Thanks.
@ash2k Do you ever have a need to build windows go programs on macOS?
The FrozenDueToAge https://github.com/golang/go/issues/12888 having mentioned cross-compiling to Windows.
@forskning As the issue #12888 saying:
In order to use cgo when cross-compiling, you need to set the CC environment variable to a Darwin -> GNU/Linux cross-compiler. You are using a Darwin native compiler, which can not work. Even if the build succeeded, the resulting code would not run on GNU/Lin
How do i get the Darwin -> GNU/Linux cross-compiler ? thx!
@mrhoric the last line of the shell output from https://github.com/golang/go/issues/22462#issuecomment-339882044 indicates that crosstool-NG was utilised
Still not solved 😢
CGO_ENABLED=0
export GOOS=linux GOARCH=arm CGO_ENABLED=0
➜ allow_by_dns_query git:(master) ✗ go build -buildmode=plugin -trimpath -o zabita_rule.so zabita_rule.go
# command-line-arguments
loadinternal: cannot find runtime/cgo
/opt/homebrew/Cellar/go/1.18.4/libexec/pkg/tool/darwin_arm64/link: running clang failed: exit status 1
clang: error: invalid linker name in argument '-fuse-ld=gold'
CGO_ENABLED=1
➜ allow_by_dns_query git:(master) ✗ export GOOS=linux GOARCH=arm CGO_ENABLED=1
➜ allow_by_dns_query git:(master) ✗ go build -buildmode=plugin -trimpath -o zabita_rule.so zabita_rule.go
# runtime/cgo
clang: error: argument unused during compilation: '-marm' [-Werror,-Wunused-command-line-argument]
GO111MODULE=""
GOARCH="arm"
GOBIN=""
GOCACHE="/Users/ahmet/Library/Caches/go-build"
GOENV="/Users/ahmet/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/ahmet/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/Users/ahmet/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.18.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.18.4/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18.4"
GCCGO="gccgo"
GOARM="5"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/ahmet/Desktop/ozer/zabita/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -marm -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4v/6v36n2h552n4p33y4dz41f8c0000gq/T/go-build1389646958=/tmp/go-build -gno-record-gcc-switches"
Still have this issue in golang 1.19 😭 Hope someone kindly fix this soon
Base on the comments on related issues, I think we just need to set CGO_ENABLED=1
and CC=[your-compiler]
. My problem is I don't know the executable name for this Mac OS cross-compiler. I've installed this using brew but I can't seem to make it work with:
CGO_ENABLED=1 CC=arm-linux-gnueabihf-cc GOOS=linux GOARCH=arm GOARM=7 go build --buildmode=plugin
Anybody know what should be the value for CC=?
env variable? I'm in Mac OS ventura apple silicon if that matters.
What version of Go are you using (
go version
)?go version go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?macOS Sierra 10.12.6 with latest Xcode 9.0.1 and Command Line Tools installed.
What did you do?
With explicit
CGO_ENABLED=1
I get:What did you expect to see?
Successfully compiled plugin.
What did you see instead?
Failures.