dqcuq4138 2015-07-10 08:05
浏览 56
已采纳

在Linux中运行Google Go Binary的无效参数

I’ve written a very small application in Go, and configured an AWS Linux AMI to host. The application is a very simple web server. I’ve installed Go on the Linux VM by following the instructions in the official documentation to the letter. My application runs as expected when invoked with the “go run main.go” command.

However, I receive an “Invalid argument” error when I attempt to manually launch the binary file generated as a result of running “go install”. Instead, if I run “go build” (which I understand to be essentially the same thing, with a few exceptions) and then invoke the resulting binary, the application launches as expected.

I’m invoking the file from within the $GOPATH/bin/ folder as follows:

./myapp

I’ve also added $GOPATH/bin to the $PATH variable. I have also moved the binary from $GOPATH/bin/ to the src folder, and successfully run it from there.

The Linux instance is a 64-bit instance, and I have installed the corresponding Go 64-bit installation.

  • 写回答

1条回答 默认 最新

  • dousui8263 2015-07-10 09:33
    关注

    go build builds everything (that is, all dependent packages), then produces the resulting executable files and then discards the intermediate results (see this for an alternative take; also consider carefully reading outputs of go help build and go help install).

    go install, on the contrary, uses precompiled versions of the dependent packages, if it finds them; otherwise it builds them as well, and installs under $PATH/pkg. Hence I might suggest that go install sees some outdated packages which screw the resulting build.

    Consider running go install ./... in your $GOPATH/src. Or may be just selective go install uri/of/the/package for each dependent package, and then retry building the executable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?