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
Open Visual Studio Code, navigate to code > preferences > extensions and search for the Go for Visual Studio Code extension. The extension depends on some extra command-line tools. If they are missing you get to see a pop-up, the first time you open a directory or workspace which contains Go code. Click Install All .
From the command line in the hello directory, run the go build command to compile the code into an executable. From the command line in the hello directory, run the new hello executable to confirm that the code works.
Simply put, if your source file includes the suffix, _$GOOS.go then it will only be built on that platform. All other platforms will behave as if the file is not present. The same applies for _$GOARCH.go . The two can be combined as _$GOOS_$GOARCH.go , but not _$GOARCH_$GOOS.go .
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 executable:
chmod +x path-to-binary
and then run it in terminal:
path-to-binary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With