Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile a Go package on Windows?

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.

like image 359
Wasly Sevenx Avatar asked Jul 04 '12 02:07

Wasly Sevenx


People also ask

How do I run a go program on Windows?

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.

Can go be compiled to EXE?

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.

How can you make a go file build only on Windows?

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.


2 Answers

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

like image 144
peterSO Avatar answered Oct 23 '22 00:10

peterSO


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.

like image 34
jdi Avatar answered Oct 22 '22 23:10

jdi