* Tianon Gravi: > I'm not positive whether all were required for this to work, but given > that it _did_ work, I think this is in the realm of possible with the > changes of Go 1.5 and am inclined to close this bug as "fixed" -- > thoughts? :)
Unfortunately, it's not that easy. :-( Last time I checked, I was able to "go build" a package from $GOPATH, but not "go install" because "go install" wanted to install the cross-built standard library for the other architecture to $GOROOT, even if no CGO was involved. This is still the case with golang 2:1.5.3-1. For demonstration purposes, here's what I tried with something similar to your test case: 1. Set up an empty GOPATH with a package directory structure: ,---- | $ mkdir -p gopath/src/example.org/foo | $ cat > gopath/src/example.org/foo/test.go | package foo | | // #include <stdio.h> | import "C" | | func Foo() { | C.fopen(C.CString("test.txt"), C.CString("r")) | } `---- 2. "go install" for the native environment ,---- | $ GOPATH=`pwd`/gopath go install -v -x example.org/foo | WORK=/tmp/go-build567075617 | example.org/foo | mkdir -p $WORK/example.org/foo/_obj/ | mkdir -p $WORK/example.org/ | cd /home/bengen/tmp/go-cross-test/gopath/src/example.org/foo | CGO_LDFLAGS="-g" "-O2" /usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/example.org/foo/_obj/ -importpath example.org/foo -- -I $WORK/example.org/foo/_obj/ test.go | gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -print-libgcc-file-name | gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -I $WORK/example.org/foo/_obj/ -g -O2 -o $WORK/example.org/foo/_obj/_cgo_main.o -c $WORK/example.org/foo/_obj/_cgo_main.c | gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -I $WORK/example.org/foo/_obj/ -g -O2 -o $WORK/example.org/foo/_obj/_cgo_export.o -c $WORK/example.org/foo/_obj/_cgo_export.c | gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -I $WORK/example.org/foo/_obj/ -g -O2 -o $WORK/example.org/foo/_obj/test.cgo2.o -c $WORK/example.org/foo/_obj/test.cgo2.c | gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -o $WORK/example.org/foo/_obj/_cgo_.o $WORK/example.org/foo/_obj/_cgo_main.o $WORK/example.org/foo/_obj/_cgo_export.o $WORK/example.org/foo/_obj/test.cgo2.o -g -O2 | /usr/lib/go/pkg/tool/linux_amd64/cgo -objdir $WORK/example.org/foo/_obj/ -dynpackage foo -dynimport $WORK/example.org/foo/_obj/_cgo_.o -dynout $WORK/example.org/foo/_obj/_cgo_import.go | gcc -I . -fPIC -m64 -pthread -fmessage-length=0 -o $WORK/example.org/foo/_obj/_all.o $WORK/example.org/foo/_obj/_cgo_export.o $WORK/example.org/foo/_obj/test.cgo2.o -g -O2 -Wl,-r -nostdlib /usr/lib/gcc/x86_64-linux-gnu/5/libgcc.a -Wl,--build-id=none | /usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/example.org/foo.a -trimpath $WORK -p example.org/foo -buildid bd90e3598b891a30d744d0b538320556a1cbce19 -D _/home/bengen/tmp/go-cross-test/gopath/src/example.org/foo -I $WORK -pack $WORK/example.org/foo/_obj/_cgo_gotypes.go $WORK/example.org/foo/_obj/test.cgo1.go $WORK/example.org/foo/_obj/_cgo_import.go | pack r $WORK/example.org/foo.a $WORK/example.org/foo/_obj/_all.o # internal | mkdir -p /home/bengen/tmp/go-cross-test/gopath/pkg/linux_amd64/example.org/ | mv $WORK/example.org/foo.a /home/bengen/tmp/go-cross-test/gopath/pkg/linux_amd64/example.org/foo.a | $ find gopath/pkg | gopath/pkg | gopath/pkg/linux_amd64 | gopath/pkg/linux_amd64/example.org | gopath/pkg/linux_amd64/example.org/foo.a `---- 3. "go install" for different GOOS/GOARCH: ,---- | $ GOPATH=`pwd`/gopath GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc go install -v -x example.org/foo | runtime | mkdir -p $WORK/runtime/_obj/ | mkdir -p $WORK/ | cd /usr/lib/go/src/runtime | /usr/lib/go/pkg/tool/linux_amd64/compile -o $WORK/runtime.a -trimpath $WORK -p runtime -+ -buildid c465ba923d1f8f93ffbb38a56ab921e0ac0c161d -D _/usr/lib/go/src/runtime -I $WORK -pack -asmhdr $WORK/runtime/_obj/go_asm.h ./alg.go ./arch1_386.go ./arch_386.go ./atomic_386.go ./atomic_pointer.go ./cgo.go ./cgocall.go ./cgocallback.go ./chan.go ./compiler.go ./complex.go ./cpuprof.go ./cputicks.go ./debug.go ./defs_windows_386.go ./env_posix.go ./error.go ./extern.go ./hash32.go ./hashmap.go ./hashmap_fast.go ./heapdump.go ./iface.go ./lfstack.go ./lfstack_32bit.go ./lock_sema.go ./malloc.go ./mbarrier.go ./mbitmap.go ./mcache.go ./mcentral.go ./mem_windows.go ./mfinal.go ./mfixalloc.go ./mgc.go ./mgcmark.go ./mgcsweep.go ./mgcwork.go ./mheap.go ./mprof.go ./msize.go ./mstats.go ./netpoll.go ./netpoll_windows.go ./os1_windows.go ./os2_windows.go ./os_windows.go ./panic.go ./panic1.go ./parfor.go ./print1.go ./print1_write.go ./proc.go ./proc1.go ./race0.go ./rdebug.go ./rune.go ./runtime.go ./runtime1.go ./runtime2.go ./select.go ./sema.go ./signal_windows.go ./sigqueue.go ./slice.go ./softfloat64.go ./sqrt.go ./stack1.go ./stack2.go ./string.go ./string1.go ./stubs.go ./stubs32.go ./symtab.go ./sys_x86.go ./syscall_windows.go ./time.go ./trace.go ./traceback.go ./type.go ./typekind.go ./typekind1.go ./unaligned1.go ./vdso_none.go ./vlrt.go ./wbfat.go ./zcallback_windows.go ./zgoarch_386.go ./zgoos_windows.go ./zversion.go | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/asm.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./asm.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/asm_386.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./asm_386.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/duff_386.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./duff_386.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/memclr_386.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./memclr_386.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/memmove_386.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./memmove_386.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/rt0_windows_386.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./rt0_windows_386.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/sys_windows_386.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./sys_windows_386.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/vlop_386.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./vlop_386.s | /usr/lib/go/pkg/tool/linux_amd64/asm -o $WORK/runtime/_obj/zcallback_windows.o -trimpath $WORK -I $WORK/runtime/_obj/ -I /usr/lib/go/pkg/include -D GOOS_windows -D GOARCH_386 ./zcallback_windows.s | pack r $WORK/runtime.a $WORK/runtime/_obj/asm.o $WORK/runtime/_obj/asm_386.o $WORK/runtime/_obj/duff_386.o $WORK/runtime/_obj/memclr_386.o $WORK/runtime/_obj/memmove_386.o $WORK/runtime/_obj/rt0_windows_386.o $WORK/runtime/_obj/sys_windows_386.o $WORK/runtime/_obj/vlop_386.o $WORK/runtime/_obj/zcallback_windows.o # internal | mkdir -p /usr/lib/go/pkg/windows_386/ | go install runtime: mkdir /usr/lib/go/pkg/windows_386/: permission denied `---- Cheers, -Hilko