构建后无法执行 Golang 可执行文件。

huangapple go评论96阅读模式
英文:

Cannot execute golang executable after building

问题

我必须先说明一下,我在使用Go方面是初学者。我克隆了一个项目,可以在https://gitlab.com/gitlab-org/security-products/analyzers/common.git找到。

在构建之前,go的环境变量为GOARCH=amd64 GOOS=linux

克隆项目后,我进入包含go文件的目录,即command/,然后运行以下命令go build -o analyzer

这将输出一个名为analyzer的文件。我注意到的一个问题是,除非我运行chmod +x analyzer,否则无法执行此文件。

当我执行该二进制文件时,出现错误:

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

I have to preface that I am beginner when it comes to using Go. I have cloned a project that can be found at https://gitlab.com/gitlab-org/security-products/analyzers/common.git

Before building, the environment variables for go are GOARCH=amd64 GOOS=linux.

After cloning the project I navigate to into the directory that has go files, that is command/, and run the following command go build -o analyzer

This outputs a file called analyzer. The one I noticed is that I can't execute this file unless I do chmod +x analyzer.

When I do execute the that binary I get an error

./analyzer: line 1: syntax error near unexpected token `newline&#39;
./analyzer: line 1: `!&lt;arch&gt;&#39;

答案1

得分: 3

那个包不是一个主要的包。只有主要的包(带有package main语句的包)才会构建成可执行文件。

英文:

That package is not a main package. Only main packages (with the package main statement) will build into executable files.

huangapple
  • 本文由 发表于 2021年6月7日 03:50:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/67863141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定