The builtin println function is deprecated and should not be used. Instead, use fmt.Println. In your case, because you’re using formatting directives, use fmt.Printf to change this:
println("cmd.Run() failed with %s\n", err)
to this:
fmt.Printf("cmd.Run() failed with %v\n", err)
On my computer, that gets me this message:
> go run .\main.go
darwin
android
cmd.Run() failed with exit status 2
linux
To get more information, check the stdout and stderr from the command:
> go run .\main.go
darwin
android
cmd.Run() failed with exit status 2:
output:
# command-line-arguments
c:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exec: "gcc": executable file not found in %PATH%
linux
Thanks a lot for the details answer, in my case I got this error:
C:\Users\hasan\Documents\GoPlay\Env>go run build.go
darwin
android
cmd.Run() failed with exit status 2:
output:
# command-line-arguments
c:\go\pkg\tool\windows_amd64\link.exe: running gcc failed: exit status 1
gcc: error: unrecognized command line option '-rdynamic'
I tried same at Mac OS, and got:
cmd.Run() failed with exit status 2:
output:
# command-line-arguments
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: unknown option: -z
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And tried at Linux (Ubuntu WSL at Win10) and got:
# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/tmp/go-link-178415548/go.o:(.data+0x0): undefined reference to `x_cgo_callers'
/tmp/go-link-178415548/go.o:(.data+0x8): undefined reference to `x_cgo_init'
/tmp/go-link-178415548/go.o:(.data+0x10): undefined reference to `x_cgo_mmap'
/tmp/go-link-178415548/go.o:(.data+0x18): undefined reference to `x_cgo_munmap'
/tmp/go-link-178415548/go.o:(.data+0x20): undefined reference to `x_cgo_notify_runtime_init_done'
/tmp/go-link-178415548/go.o:(.data+0x28): undefined reference to `x_cgo_sigaction'
/tmp/go-link-178415548/go.o:(.data+0x30): undefined reference to `x_cgo_thread_start'
/tmp/go-link-178415548/go.o:(.data+0x38): undefined reference to `x_cgo_setenv'
/tmp/go-link-178415548/go.o:(.data+0x40): undefined reference to `x_cgo_unsetenv'
/tmp/go-link-178415548/go.o:(.data+0x48): undefined reference to `_cgo_yield'
collect2: error: ld returned 1 exit status