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.

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

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊