英文:
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'
./analyzer: line 1: `!<arch>'
答案1
得分: 3
那个包不是一个主要的包。只有主要的包(带有package main
语句的包)才会构建成可执行文件。
英文:
That package is not a main package. Only main packages (with the package main
statement) will build into executable files.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论