Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not able to find executable/binary file after "go build" command

Tags:

linux

go

I am new to golang and I have a single package go file "hello_world.go" which I am compiling via "go build hello_world.go". After this I expect to see executable "hello_world". But I donot see it.

I tried options -x and -v with "go build " and below is the output

go build -x -v hello_world.go
WORK=/tmp/go-build697702511
command-line-arguments
mkdir -p $WORK/command-line-arguments/_obj/
mkdir -p $WORK/
cd /home/vignesh/exercism/go/hello-world
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/command-line- arguments.a -trimpath $WORK -goversion go1.9.2 -p command-line-arguments -complete -buildid 1d40767f999b0c5cb646b061911455ddde0101d2 -D _/home/vignesh/exercism/go/hello-world -I $WORK -pack ./hello_world.go

below is the content of my working directory after above two "go build" operations

-rw------- 1 vignesh vignesh  208 Jul 17 20:50 .solution.json
-rw-rw-r-- 1 vignesh vignesh 1451 Jul 17 20:50 README.md
-rw-rw-r-- 1 vignesh vignesh 1311 Jul 17 20:50 hello_test.go_bkp
drwxr-xr-x 4 vignesh vignesh 4096 Jul 18 18:27 ..
-rw-rw-r-- 1 vignesh vignesh 1311 Jul 18 20:27 hello_test.go
-rw-rw-r-- 1 vignesh vignesh  684 Jul 18 20:29 hello_world.go
drwxr-xr-x 2 vignesh vignesh 4096 Jul 18 20:57 .

I then tried "go build -o aaa hello_world.go" which generated binary file "aaa", which on execution gave following errors:

./aaa: line 1: syntax error near unexpected token `newline'
./aaa: line 1: `!<arch>'

below is the output of "go env "

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/vignesh/exercism/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build845978294=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

Kindly help me with a fix or any sugestions to debug this issue.

Thanks in advance

like image 919
Vignesh k Avatar asked Dec 13 '22 15:12

Vignesh k


1 Answers

You're building a package that isn't main, so there is no executable to create. Setting the -o flag forces build to output the object file that would otherwise be discarded, but that is not an executable. Go object files start with the string !<arch>\n, which is why you receive that error when you attempt to execute it.

Change your package name to main.

like image 110
JimB Avatar answered Dec 18 '22 00:12

JimB