Fortunately, Gary Kramlich who is one of Pidgin‘s core developers, has done all the hard work for us and created the Debian based msys2-cross Container. The crosscompile.bash script has been removed to prevent accidents from people coming here from outdated links. How do I cross compile a Go project on Linux to generate an executable for running on Windows? As an example, even from a development Windows 7 32-bit machine, you can build binaries for both 64 bit Linux and Windows 2012 Servers. Let’s use a simple go file as an example. Debian based distributions come fortunately with Multiarch support. A nice feature of the Go language is the ability to build binaries for multiple platforms directly from a single source system. In case you don't use pkg-config and haven't specified LDFLAGS with a cgo directive in your source code, you can specify the locations of the libraries and header files with the -ldflags flag: While we could certainly install everything required for cross compiling on our host system, That's what this article has been written for. Both of them are written in C. I personally like Debian flavored Linux systems. Cross compiling cgo applications from Linux host systems for Microsoft Windows is a bit more complicated and requires a few extra steps. arm64) on our host system: After updating the packages sources with apt-get update we are able to install now pre-compiled library packages for the target system. We use the variable GOOS for the target operating system, and GOARCH for the target architecture. Over the years, Docker has become one of my indispensible tools. https://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5, https://github.com/golang/go/wiki/WindowsCrossCompiling, https://www.infoq.com/news/2015/08/go-1-5, http://stackoverflow.com/questions/33113190/how-to-create-a-statically-linked-golang-executable-with-go-1-5, http://matthewkwilliams.com/index.php/2014/09/28/go-executables-are-statically-linked-except-when-they-are-not/, http://stackoverflow.com/questions/16747021/how-do-you-statically-link-a-c-library-in-go-using-cgo, https://www.osso.nl/blog/golang-statically-linked/, https://blog.codeship.com/building-minimal-docker-containers-for-go-applications/, https://stackoverflow.com/questions/16747021/how-do-you-statically-link-a-c-library-in-go-using-cgo, https://github.com/golang/go/issues/12808, https://news.ycombinator.com/item?id=7677699, https://stackoverflow.com/questions/33113190/how-to-create-a-statically-linked-golang-executable-with-go-1-5, dh1tw.de Tobias Wellnitz, cross-compling golang with static c libs using Docker, go build -a -tags netgo (for further hint on static linking, but CGO_ENABLED=0 has been enough for me), GoLang: Installing the Go Programming language on Ubuntu 14.04, GoLang: Vendor directory for github branches other than master, GoLang: Installing the Go Programming language on Ubuntu, GoLang: Installing the Go Programming language on Ubuntu 16.04, Docker: Base image when deploying a GoLang binary in a container, GoLang: Using multi-stage builds to create clean Docker images, Git: Incorporating multiple pull requests from the main project into your fork, Git: Identifying files that .gitignore is purposely skipping, Bash: Fixing an ASCII text file changed with Unicode character sequences, Ubuntu: Using add-apt-repository with a proxy, Bash: Sharing a terminal screen among users with tmux, CloudFoundry: Determining buildpack used by application, Bash: Using logic expressions as a shorthand for if-then-else control, Python: Publishing and Consuming from RabbitMQ using Python, RabbitMQ: Deleting a ghost queue that cannot be removed at the GUI/CLI, Bash: output all lines before/after line identified by regex, Ubuntu: Adding a root certificate authority, Bash: Examining each certificate in a yaml file using sed and openssl, KVM: Testing cloud-init locally using KVM for a RHEL cloud image, Linux: Introducing latency and packet loss into network for testing, KVM: Testing cloud-init locally using KVM for a CentOS cloud image, KVM: Testing cloud-init locally using KVM for an Ubuntu cloud image, KVM: Terraform and cloud-init to create local KVM resources, Bash: Associative array initialization and usage, Bash: Appending to existing values using sed capture group, Bash: Using BASH_REMATCH to pull capture groups from a regex, Bash: Renaming files using shell parameter expansion, GoLang: Go modules for package management during a multi-stage Docker build, Docker: Working with local volumes and tmpfs mounts, Bash: Using shell or environment variables in awk output, Docker: Placing limits on cpu usage in containers, Docker: Placing limits on container memory using cgroups, Bash: Skipping lines at the top or bottom of a stream, Linux: Outputting single quotes in awk output, Docker: Use overlay2 with an xfs backing filesystem to limit rootfs size, Linux: Mounting a loopback ext4/xfs filesystem to isolate or enforce storage limits, Linux: Using xfs project quotas to limit capacity within a subdirectory, Bash: Outputting text in color for readability, Bash: Performing floating arithmetic using bc, Python: Using Flask to stream chunked dynamic content to end users, Docker: Running a Postfix container for testing mail during development, Python: Sending HTML emails via Gmail API or SMTP relay, Zabbix: Using Docker Compose to install and upgrade Zabbix, Bash: setting and replacing values in a properties file use sed, Bash: Running command on quoted list of parameters using xargs, Docker: Installing Docker CE on Ubuntu bionic 18.04, Python: Using a custom decorator to inspect function arguments, Python: Using inspection to view the parameters of a function, Python: Getting live output from subprocess using poll, Python: Parsing command line arguments with argparse, PowerShell: Creating a self-signed certificate using Powershell without makecert or IIS, KVM: Creating a guest VM on a network in routed mode, Ubuntu: Debug iptables by inserting a log rule, KVM: Creating a guest VM on a NAT network, KVM: Creating a bridged network with NetPlan on Ubuntu bionic, Git: BFG for removing secrets from entire git history, WordPress: Cloning your WordPress site locally using Docker Compose, Python: JSONPath to extract vCenter information using govc, Python: Querying JSON files with JSONPath using jsonpath_rw_ext, VMware: Using the govc CLI to automate vCenter commands, Linux: 7zip to split archives for use on Windows, Linux: sed to cleanup json that has errant text surrounding it, KVM: virt-manager to connect to a remote console using qemu+ssh, Ubuntu: Create an NFS server mount on Ubuntu, Linux: Use stat to verify permissions and ownership, Kubernetes: running Minikube locally on Ubuntu using KVM, Ubuntu: X2Go on Ubuntu bionic for remote desktop access, Git: client error, server certificate verification failed, CloudFoundry: CLI error, unexpected end of JSON input, Ubuntu: apt-get error, yarn signature verification, CloudFoundry: The lifecycle of a simple BOSH release, AWS: Bash helper functions for common AWS CLI calls, CloudFoundry: Installing a BOSH Director on AWS, AWS: Installing the AWS SDK for Python on Ubuntu, Java: FTP with an HTTP proxy using the CONNECT method, Git: Contributing to a git project using a pull request, Ubuntu: Auditing sudo commands and forwarding audit logs using syslog, Python: Calling python functions from mako templates, Git: Sharing a single git controlled folder among a group under Linux, Git: Forcing git to use vim for commit messages, Ubuntu: Determining the package origin of a file, KVM: Deploy the VMware vCenter appliance using the CLI installer, Linux: Using GPG encrypted credentials for enhanced security, Linux: Using zip/unzip to add, update, and remove files from a Java jar/war, Linux: Using sed to insert lines before or after a match, PowerShell: Create Windows Scheduled Task to run Powershell script every hour, KVM: Using dnsmasq for libvirt DNS resolution, Linux: Copy a directory preserving ownership, permissions, and modification date, Ruby: Copying gems to hosts with limited internet access, Ruby: Creating Selenium tests using headless Chrome and Ruby2, Ubuntu: X11 forwarding to view GUI applications running on server hosts, Linux: Excluding files based on extension and age with tar, SaltStack: Escaping dollar signs in cmd.run parameters to avoid interpolation, OpenWrt: Archive router configs for backup, PuTTy: Bulk import PuTTy session definitions into the registry using Powershell, KVM: Creating an Ubuntu VM with console-only access, ELK: Deleting unassigned shards to restore cluster health, Ubuntu: Customizing and repacking a deb file.