getlantern / systray

a cross platfrom Go library to place an icon and menu in the notification area
Apache License 2.0
3.29k stars 456 forks source link

Error compiling from Linux for Darwin #34

Open vcraescu opened 6 years ago

vcraescu commented 6 years ago
# github.com/vcraescu/holy-internet/vendor/github.com/getlantern/systray
vendor/github.com/getlantern/systray/systray.go:81:2: undefined: nativeLoop
vendor/github.com/getlantern/systray/systray.go:87:3: undefined: quit
vendor/github.com/getlantern/systray/systray.go:105:2: undefined: addSeparator
vendor/github.com/getlantern/systray/systray.go:139:2: undefined: hideMenuItem
vendor/github.com/getlantern/systray/systray.go:144:2: undefined: showMenuItem
vendor/github.com/getlantern/systray/systray.go:169:2: undefined: addOrUpdateMenuItem

Any idea?

Thanks!

mickael-kerjean commented 6 years ago

Same here, did you find a fix?

anjannath commented 6 years ago

same here, couple of reason for this not working, first we need to enable cgo then we need proper darwin libraries, i haven't been able to find a fix myself, but in https://github.com/getlantern/systray/blob/master/systray_nonwindows.go the comments indicate some cflags and ldflags but that gives another error like the following:

[example]$ CC=gcc CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -gccgoflags="-DDARWIN -x objective-c -fobjc-arc" -ldflags="framework Cocoa" main.go
go build: when using gc toolchain, please pass compile flags using -gcflags, and linker flags using -ldflags
# net
/usr/lib/golang/src/net/cgo_bsd.go:15:72: could not determine kind of name for C.AI_MASK
# os/user
/usr/lib/golang/src/os/user/getgrouplist_darwin.go: In function ‘mygetgrouplist’:
/usr/lib/golang/src/os/user/getgrouplist_darwin.go:14:11: warning: implicit declaration of function ‘getgrouplist’; did you mean ‘mygetgrouplist’? [-Wimplicit-function-declaration]
  int rv = getgrouplist(user, (int) group, buf, ngroups);
           ^~~~~~~~~~~~
           mygetgrouplist

@oxtoacart Any ideas what is going on here?

gravataLonga commented 4 years ago

Any solution to actually build to Darwin?

davidnewhall commented 3 years ago

Same problem building linux from macOS. Now that I've added GUI code to my app, my CI/CD pipeline can no longer cross compile the binaries. Leaves me in quite a pickle.

koltyakov commented 3 years ago

If you’re on a macOS it’s less painful to cross-compile manually. Cross-compilation to Windows works OOTB. For Linux, you’d need Docker on a macOS and bit of scripting. For CI/CD pipeline, won’t do it without different platform agent matrix. Maybe it’ll be useful this is how I bootstrap cross-compilation (from macOS host) for a small project with systray.

davidnewhall commented 3 years ago

@koltyakov - Really appreciate that. :) I managed to get the pipeline split into one build for everything else and one for macOS (on a Mac), so I've overcome my pickle.

ForestJohnson commented 3 years ago

why was this comment deleted? http://web.archive.org/web/20201221103316/https://github.com/getlantern/systray/issues/34

nadavami commented 3 years ago

Not 100% same use-case, but I ran into the same issue when trying to cross compile a darwin amd64 binary on darwin arm64.

I was able to resolve the issue by building it using the following command: CC=gcc CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -gccgoflags="-DDARWIN -x objective-c -fobjc-arc" -ldflags="framework=Cocoa" .

davidrenne commented 2 years ago

Not 100% same use-case, but I ran into the same issue when trying to cross compile a darwin amd64 binary on darwin arm64.

I was able to resolve the issue by building it using the following command: CC=gcc CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -gccgoflags="-DDARWIN -x objective-c -fobjc-arc" -ldflags="framework=Cocoa" .

@nadavami Im trying to cross compile from intel mac to arm64 for m1's and tried some of these flags but I get

GOOS=darwin GOARCH=arm64 go build -a -tags netgo -gccgoflags="-DDARWIN -x objective-c -fobjc-arc" -ldflags "framework=Cocoa -s -w" -o AppleSilicon.app/Contents/MacOS/Bridge
go build: when using gc toolchain, please pass compile flags using -gcflags, and linker flags using -ldflags
# github.com/getlantern/systray
../../go/pkg/mod/github.com/getlantern/systray@v1.2.1/systray.go:78:2: undefined: nativeLoop
../../go/pkg/mod/github.com/getlantern/systray@v1.2.1/systray.go:106:2: undefined: registerSystray
../../go/pkg/mod/github.com/getlantern/systray@v1.2.1/systray.go:111:14: undefined: quit
../../go/pkg/mod/github.com/getlantern/systray@v1.2.1/systray.go:136:2: undefined: addSeparator
../../go/pkg/mod/github.com/getlantern/systray@v1.2.1/systray.go:190:2: undefined: hideMenuItem
../../go/pkg/mod/github.com/getlantern/systray@v1.2.1/systray.go:195:2: undefined: showMenuItem
../../go/pkg/mod/github.com/getlantern/systray@v1.2.1/systray.go:220:2: undefined: addOrUpdateMenuItem

Any ideas? Maybe I have to setup some sort of arm docker container to get this to compile.