Golang构建:从特定路径执行可执行文件时获取'语法错误:换行意外“

问题描述 投票:1回答:1

我的应用程序打包如下:

|-cmd/
|-cmd/application/ <- this contains the main.go and other files
|-internal/ <- contains internal dependencies
|-vendor/ <- contains third party libraries

从根/运行以下命令时:

go build cmd/application/*.go

它生成一个可行的可执行文件。但是当从/cmd/application里面输入以下命令时:

go build my_app_custom_name

我得到Syntax error: newline unexpected错误,好像它不再是bash可执行文件了。

go
1个回答
4
投票

在使用标志-v和-x之后,在指示@Volker的帮助下,我发现我正在命名包“myapp”而不是“主”应该是。现在它工作得很好。

正如@Kaedys和@JimB所说,最好使用标准表单来构建应用程序:

go build // Method one from inside directory with go files
go build full/import/path/of/package/to/build // second method

请注意,这是How to write Go code中推荐的方式

另一种构建方法是在你去包的目录中使用go build .go build *.go

© www.soinside.com 2019 - 2024. All rights reserved.