douwu8060 2018-07-18 16:14
浏览 211
已采纳

“执行构建”命令后无法找到可执行文件/二进制文件

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

  • 写回答

1条回答

  • dongmijgnnq0118 2018-07-18 16:31
    关注

    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> , which is why you receive that error when you attempt to execute it.

    Change your package name to main.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿