The documentation is all for Mac OS X and Linux, and I wish to know how to compile a Go package on the Windows platform. On Windows, I do not know how to write the make file and which tool to use to make it.
It seems that there is not a tool named make or go make to use with the installation file of Go development tools.
Run Go Program To run a go program, create a file with an extension .go and write your golang code in that file. For example, we will create a file named helloworld.go and write the following code in it. Now open command prompt and navigate to the location of helloworld.go file.
The go run command compiles and runs the Go package from a list of .go source files from the new hello directory you created and the path you imported. But, you can also use go build to make an executable file that can save you some time.
You can set either the GOOS or GOARCH environment variables to build for a different platform using go build . If you are not using a Windows system, build a windows binary of app by setting the GOOS environment variable to windows when running the go build command: GOOS=windows go build.
Compiling a Go package on Windows is like compiling a Go package on Linux or Mac OS X. Use the go build
command. There is no make file.
Here are some instructions.
Getting Started
How to Write Go Code
Compile packages and dependencies
There are no more Makefiles needed in Go, so the make
tool isn't necessary. You also do not need cygwin.
If you do not seem to have a valid go
command in your windows shell, then try following the official docs on installing Go for windows
Zip archive
Extract the zip file to the directory of your choice (we suggest c:\Go).
If you chose a directory other than c:\Go, you must set the GOROOT environment variable to your chosen path.
Add the bin subdirectory of your Go root (for example, c:\Go\bin) to to your PATH environment variable.
MSI installer (experimental)
Open the MSI file and follow the prompts to install the Go tools. By default, the installer puts the Go distribution in c:\Go.
The installer should put the c:\Go\bin directory in your PATH environment variable. You may need to restart any open command prompts for the change to take effect.
Setting environment variables under Windows
Under Windows, you may set environment variables through the "Environment Variables" button on the "Advanced" tab of the "System" control panel. Some versions of Windows provide this control panel through the "Advanced System Settings" option inside the "System" control panel.
The last section is important. Your windows PATH environment variable needs to have C:\Go\bin
, so that you will have go
in your path.
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