2

I am trying to run a simple helloworld.go on RHEL 6.8.

% cat helloworld.go 
package main
import "fmt"
func main() {
    fmt.Println("hello world")
}

The GC compiler works ok

%  go build -compiler gccgo helloworld.go 
go build command-line-arguments: : fork/exec : no such file or directory

For some reason, instead, I need to compile with gccgo, but could never get it to compile. Let alone to eventually compile it statically.

% go build -compiler gccgo -gccgoflags '-static' helloworld.go
go build command-line-arguments: : fork/exec : no such file or directory
% go build -compiler gccgo -gccgoflags '-static-libgo' helloworld.go
go build command-line-arguments: : fork/exec : no such file or directory


% go version 
go version go1.7 linux/amd64
% gcc --version
gcc (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)

Insights on what the problem is would be appreciated?

chingy
  • 31
  • 1
  • 3
  • The `go` tool is trying to exec something which isn't there. Try using the `-x` to see if you can tell what is being called. – JimB Mar 17 '17 at 21:59
  • `go build -compiler gccgo -gccgoflags '-static' -x helloworld.go WORK=/tmp/go-build267938128` `mkdir -p $WORK/command-line-arguments/_obj/` `mkdir -p $WORK/command-line-arguments/_obj/exe/` `cd /root/tmp` `"" -I $WORK -c -g -m64 -fgo-relative-import-path=_/root/tmp -o $WORK/command-line-arguments/_obj/_go_.o -static ./helloworld.go go build command-line-arguments: : fork/exec : no such file or directory` – chingy Mar 20 '17 at 16:02
  • Any insight from these? @JimB (thanks and sorry for the poor formatting) – chingy Mar 20 '17 at 16:09
  • Situation should be improved by now: https://github.com/golang/go/issues/19628. – Iskander Sharipov Jan 11 '18 at 10:28

1 Answers1

-1

You should install gccgo compiler first. On my Fedora 26 desktop, run dnf install gcc-go to install.

$ which gccgo /usr/bin/gccgo go build --compiler gccgo -x WORK=/tmp/go-build848309745 mkdir -p $WORK/_/home/sam/sandbox/go/src/hello/_obj/ mkdir -p $WORK/_/home/sam/sandbox/go/src/hello/_obj/exe/ cd /home/sam/sandbox/go/src/hello /usr/bin/gccgo -I $WORK -c -g -m64 -fgo-relative-import-path=_/home/sam/sandbox/go/src/hello -o $WORK/_/home/sam/sandbox/go/src/hello/_obj/_go_.o ./helloworld.go ar rc $WORK/_/home/sam/sandbox/go/src/libhello.a $WORK/_/home/sam/sandbox/go/src/hello/_obj/_go_.o cd . /usr/bin/gccgo -o $WORK/_/home/sam/sandbox/go/src/hello/_obj/exe/a.out $WORK/_/home/sam/sandbox/go/src/hello/_obj/_go_.o -Wl,-( -m64 -Wl,--whole-archive -Wl,--no-whole-archive -Wl,-) cp $WORK/_/home/sam/sandbox/go/src/hello/_obj/exe/a.out hello

If you need to link static, package glibc-static and libgo-static are required to be installed too. After installed them, compile using gccgo and link statically by

$ go build -compiler gccgo -x --gccgoflags "-static" WORK=/tmp/go-build815863722 mkdir -p $WORK/_/home/sam/sandbox/go/src/hello/_obj/ mkdir -p $WORK/_/home/sam/sandbox/go/src/hello/_obj/exe/ cd /home/sam/sandbox/go/src/hello /usr/bin/gccgo -I $WORK -c -g -m64 -fgo-relative-import-path=_/home/sam/sandbox/go/src/hello -o $WORK/_/home/sam/sandbox/go/src/hello/_obj/_go_.o -static ./helloworld.go ar rc $WORK/_/home/sam/sandbox/go/src/libhello.a $WORK/_/home/sam/sandbox/go/src/hello/_obj/_go_.o cd . /usr/bin/gccgo -o $WORK/_/home/sam/sandbox/go/src/hello/_obj/exe/a.out $WORK/_/home/sam/sandbox/go/src/hello/_obj/_go_.o -Wl,-( -m64 -Wl,--whole-archive -Wl,--no-whole-archive -Wl,-) -static cp $WORK/_/home/sam/sandbox/go/src/hello/_obj/exe/a.out hello

samsong8610
  • 137
  • 1
  • 7