- Before you start
- Windows x64, Go SDK, Go, Python and LLVM Clang
- What you will build
- Edit and build a Go desktop window
Run the packaged window
From the Go SDK root, run the prebuilt EXE. It loads kui_c.dll beside the EXE and opens a native window; no build is needed yet.
.\bin\kui_go_hello_world.exeRead the entry point
hello_world calls Load and Init before creating Window and Document. A failed Load stops the program; owned handles use defer Close. Run enters the UI loop.
package main
import (
"log"
kui "github.com/kui-engine/kui-go/v3"
"github.com/kui-engine/kui-go/v3/examples/internal/exampleutil"
)
func main() {
if err := kui.Load(exampleutil.RuntimePath()); err != nil {
log.Fatal(err)
}
if err := kui.Init(); err != nil {
log.Fatal(err)
}
defer kui.Shutdown()
window, err := kui.NewWindow(kui.WindowProps{Title: "KUI Go SDK", Width: 960, Height: 640, Centered: true})
if err != nil {
log.Fatal(err)
}
defer window.Close()
document, err := window.Document()
if err != nil {
log.Fatal(err)
}
defer document.Close()
if err := document.LoadHTML(`<main style="padding:48px;font-family:sans-serif"><h1>Go SDK 已接入 KUI</h1><p>此程序仅通过公开 C ABI 工作。</p></main>`); err != nil {
log.Fatal(err)
}
if err := window.Show(); err != nil {
log.Fatal(err)
}
if _, err := kui.Run(); err != nil {
log.Fatal(err)
}
}
Edit and build one example
Change the HTML heading in examples/hello_world/main.go. Run these commands from the SDK root. Output goes to bin so the executable finds kui_c.dll beside it. The CC adapter handles the MSVC-target Clang arguments.
$python = (Get-Command python).Source
$adapter = (Resolve-Path .\tools\clang_go_cgo.py).Path
$env:CGO_ENABLED = '1'
$env:CC = "`"$python`" `"$adapter`""
go build -o .\bin\my_first_go.exe .\examples\hello_world
.\bin\my_first_go.exeCheck the result
Confirm that the window shows the new heading. If kui_c.dll is missing, check bin or pass its path as the first program argument. For build failures, check Go, Python and LLVM Clang.
.\bin\my_first_go.exe .\native\bin\kui_c.dllSomething unclear?
Report an issue on this page →