Golang 构建:从特定路径执行可执行文件时获取'Syntax error: newline unexpected'



我的应用程序包装如下:

|-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错误,好像它不再可执行。

在使用flags -v and -x之后,在指示@volker的帮助下,我发现我正在命名" myApp"软件包,而不是应该命名的" mainapp"。现在工作正常。

@kaedys和@jimb所说,最好使用标准表单来构建应用程序:

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

请注意,这是如何编写GO代码

的推荐方法

构建的另一种方法是使用go build .go build *.go在您使用的目录中使用。

相关内容

最新更新