Skip to content

Building and Cross Compilation

GFoniX edited this page Jan 7, 2023 · 8 revisions

Building a go application using ui, requires a c and c++ compiler toolchain.
Bellow are instructions on building an application on various platforms.

Building

Windows

  1. Download/Install MinGW-w64
  2. Set environment variables
    • CGO_ENABLED=1
    • CC=path_of_mingw_gcc_win_threads
    • CXX=path_of_mingw_g++_win_threads
  3. Run go build
  4. (Optional) specify -ldflags -H=windowsgui to prevent cmd prompt showing up when exe is ran.

One line example:

cmd /C "set CGO_ENABLED=1&& "set CC=C:\PROGRA~1\mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe&& set CXX=C:\PROGRA~1\mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exe&& go build -ldflags -H=windowsgui"

Linux

  1. Install gcc and gtk3 packages.
  2. Set environment variables
    • CGO_ENABLED=1
    • CC=gcc
    • CXX=g++

Example:

CGO_ENABLED=1 CC=gcc CXX=g++ go build

Cross compilation

From linux it is possible to cross compile binaries for windows and macOS.
Building for windows can be achieved by using mingw, building for macOS can be achieved by using osxcross and a copy of the macOS SDK.

Setting up a cross compilation toolchain can be complicated, as such a docker image has been created to make things easier.
See https://github.com/magJ/go-ui-crossbuild/ for further instructions.

Clone this wiki locally