andlabs / ui

Platform-native GUI library for Go.
Other
8.33k stars 651 forks source link

Examples fail to build on OpenBSD #353

Closed 99z closed 5 years ago

99z commented 5 years ago

go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/nsm/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="openbsd"
GOOS="openbsd"
GOPATH="/home/nsm/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/openbsd_amd64"
GCCGO="gccgo"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build422937326=/tmp/go-build -gno-record-gcc-switches"

go get -u github.com/andlabs/ui/...

# github.com/andlabs/ui
ld: error: undefined symbol: uiAreaQueueRedrawAll
>>> referenced by cgo-gcc-prolog:48
>>>               $WORK/b001/_x002.o:(_cgo_f16840e71605_Cfunc_uiAreaQueueRedrawAll)

ld: error: undefined symbol: uiAreaScrollTo
>>> referenced by cgo-gcc-prolog:64
>>>               $WORK/b001/_x002.o:(_cgo_f16840e71605_Cfunc_uiAreaScrollTo)

ld: error: undefined symbol: uiAreaSetSize
>>> referenced by cgo-gcc-prolog:78
>>>               $WORK/b001/_x002.o:(_cgo_f16840e71605_Cfunc_uiAreaSetSize)

ld: error: undefined symbol: uiNewArea
>>> referenced by cgo-gcc-prolog:93
>>>               $WORK/b001/_x002.o:(_cgo_f16840e71605_Cfunc_uiNewArea)

ld: error: undefined symbol: uiNewScrollingArea
>>> referenced by cgo-gcc-prolog:113
>>>               $WORK/b001/_x002.o:(_cgo_f16840e71605_Cfunc_uiNewScrollingArea)

ld: error: undefined symbol: uiBoxAppend
>>> referenced by cgo-gcc-prolog:51
>>>               $WORK/b001/_x004.o:(_cgo_f16840e71605_Cfunc_uiBoxAppend)

ld: error: undefined symbol: uiBoxDelete
>>> referenced by cgo-gcc-prolog:65
>>>               $WORK/b001/_x004.o:(_cgo_f16840e71605_Cfunc_uiBoxDelete)

ld: error: undefined symbol: uiBoxPadded
>>> referenced by cgo-gcc-prolog:81
>>>               $WORK/b001/_x004.o:(_cgo_f16840e71605_Cfunc_uiBoxPadded)

ld: error: undefined symbol: uiBoxSetPadded
>>> referenced by cgo-gcc-prolog:98
>>>               $WORK/b001/_x004.o:(_cgo_f16840e71605_Cfunc_uiBoxSetPadded)

ld: error: undefined symbol: uiNewHorizontalBox
>>> referenced by cgo-gcc-prolog:112
>>>               $WORK/b001/_x004.o:(_cgo_f16840e71605_Cfunc_uiNewHorizontalBox)

ld: error: undefined symbol: uiNewVerticalBox
>>> referenced by cgo-gcc-prolog:129
>>>               $WORK/b001/_x004.o:(_cgo_f16840e71605_Cfunc_uiNewVerticalBox)

ld: error: undefined symbol: uiButtonSetText
>>> referenced by cgo-gcc-prolog:61
>>>               $WORK/b001/_x005.o:(_cgo_f16840e71605_Cfunc_uiButtonSetText)

ld: error: undefined symbol: uiButtonText
>>> referenced by cgo-gcc-prolog:76
>>>               $WORK/b001/_x005.o:(_cgo_f16840e71605_Cfunc_uiButtonText)

ld: error: undefined symbol: uiFreeText
>>> referenced by cgo-gcc-prolog:91
>>>               $WORK/b001/_x005.o:(_cgo_f16840e71605_Cfunc_uiFreeText)

ld: error: undefined symbol: uiNewButton
>>> referenced by cgo-gcc-prolog:106
>>>               $WORK/b001/_x005.o:(_cgo_f16840e71605_Cfunc_uiNewButton)

ld: error: undefined symbol: uiCheckboxChecked
>>> referenced by cgo-gcc-prolog:64
>>>               $WORK/b001/_x006.o:(_cgo_f16840e71605_Cfunc_uiCheckboxChecked)

ld: error: undefined symbol: uiCheckboxSetChecked
>>> referenced by cgo-gcc-prolog:81
>>>               $WORK/b001/_x006.o:(_cgo_f16840e71605_Cfunc_uiCheckboxSetChecked)

ld: error: undefined symbol: uiCheckboxSetText
>>> referenced by cgo-gcc-prolog:94
>>>               $WORK/b001/_x006.o:(_cgo_f16840e71605_Cfunc_uiCheckboxSetText)

ld: error: undefined symbol: uiCheckboxText
>>> referenced by cgo-gcc-prolog:109
>>>               $WORK/b001/_x006.o:(_cgo_f16840e71605_Cfunc_uiCheckboxText)

ld: error: undefined symbol: uiNewCheckbox
>>> referenced by cgo-gcc-prolog:127
>>>               $WORK/b001/_x006.o:(_cgo_f16840e71605_Cfunc_uiNewCheckbox)

ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
andlabs commented 5 years ago

That is because I do not have an OpenBSD binary build. You will need to get libui Alpha 4.1 source code and build it in static mode (cmake -DBUILD_SHARED_LIBS=OFF, as Alpha 4.1 still used cmake), then copy the resultant libui.a file to libui_openbsd_ARCH.a and create an appropriatelink_openbsd_ARCH.go (copying the Linux one and changing the filenames within should be sufficient).

If there was an OpenBSD CI environment I could use I could avoid the need to manually do this in the future...

99z commented 5 years ago

Thanks for the reply - I will give this a go on Monday.

99z commented 5 years ago

This worked wonderfully.

I built Alpha 4.1 using cmake -DBUILD_SHARED_LIBS=OFF. Copied the resulting libui.a from build/meson-out to $GOPATH/src/github.com/andlabs/ui as libui_openbsd_amd64.a. Then made the link_openbsd_amd64.go file with the contents:

// +build !windows
// +build !darwin

// 11 december 2015

package ui

// #cgo LDFLAGS: ${SRCDIR}/libui_openbsd_amd64.a -lm
// #cgo pkg-config: gtk+-3.0
import "C"

Note that on {Open/Free?/Net?}BSD there is no libdl as the functionality is included inlibc, so removing -ldl was necessary.

Cheers.

andlabs commented 5 years ago

Yeah. On meson I set libdl and libm as optional dependencies specifically to avoid that issue, but we'll see what that means for the Go code or for the documentation... Either way, glad to see it works! (One day I will devote the time to set up a VM so I can do this locally again...)