我的应用程序打包如下:
|-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可执行文件了。
在使用标志-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
。