创建并运行仅适用于Mac的go build吗?

I am into a situation in which I have to run Go build on Mac OS/OS X. Build will be generated from Linux operating system & that build I have to run on Mac OS/OS X.

I have tried to generate a cross-platform build for Mac using below command and build is generated.

env GOOS=linux GOARCH=amd64 go build

This generated a Go build but I move this build to Mac it shows .dms file extension.

Now I have two questions

  • Am I generating the right build for Mac?
  • How do I run this?DMS file on Mac?

Since your binary will target OSX, you need to set GOOS to darwin, so your command will be

env GOOS=darwin GOARCH=amd64 go build

Documentation on compiler env vars is here: https://golang.org/doc/install/source#environment

To run the binary on mac you need to make sure that binary is exectable:

chmod +x path-to-binary

and then run it in terminal:

path-to-binary