-
Notifications
You must be signed in to change notification settings - Fork 647
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.
- Download/Install MinGW-w64
- Set environment variables
CGO_ENABLED=1CC=path_of_mingw_gcc_win_threadsCXX=path_of_mingw_g++_win_threads
- Run
go build - (Optional) specify
-ldflags -H=windowsguito 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"- Install gcc and gtk3 packages.
- Set environment variables
CGO_ENABLED=1CC=gccCXX=g++
Example:
CGO_ENABLED=1 CC=gcc CXX=g++ go buildFrom 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.