wails
wails copied to clipboard
Linking problems on MacOS
Description
I cannot get my app running on MacOS due to the following error. I suspect this is more related to the tooling than the app itself. But I have no idea where to look.
user@Mac1 myapp % wails dev
Wails CLI v2.6.0
Executing: go mod tidy
• Generating bindings: Done.
• Installing frontend dependencies: Done.
• Compiling frontend: Done.
> [email protected] dev
> vite dev
VITE v4.4.11 ready in 1316 ms
Vite Server URL: http://localhost:5173/
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
Running frontend DevWatcher command: 'npm run dev'
Building application for development...
• Generating bindings: Done.
• Compiling application: # something/myapp
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
duplicate symbol '_OBJC_CLASS_$_AppDelegate' in:
/var/folders/08/blr6n_6j5b52z9fl450p5f180000gp/T/go-link-4276493563/000002.o
/var/folders/08/blr6n_6j5b52z9fl450p5f180000gp/T/go-link-4276493563/000028.o
duplicate symbol '_OBJC_METACLASS_$_AppDelegate' in:
/var/folders/08/blr6n_6j5b52z9fl450p5f180000gp/T/go-link-4276493563/000002.o
/var/folders/08/blr6n_6j5b52z9fl450p5f180000gp/T/go-link-4276493563/000028.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Build error - exit status 1
No version running, build will be retriggered as soon as changes have been detected
Using DevServer URL: http://localhost:34115
Using Frontend DevServer URL: http://localhost:5173/
Using reload debounce setting of 100 milliseconds
Watching (sub)/directory: /Users/user/Development/Golang/myapp
To develop in the browser and call your bound Go methods from Javascript, navigate to: http://localhost:34115
^C
Caught quit
Development mode exited
♥ If Wails is useful to you or your company, please consider sponsoring the project:
To Reproduce
I have tested the Wails demo app and it seems to work fine. I'm not sure how to reproduce other than to just gain some insight from the error?
The app also uses systray to create an icon in the panel. "github.com/energye/systray"
Expected behaviour
The app works great on Linux and Windows.
Screenshots
No response
Attempted Fixes
No response
System Details
# Wails
Version | v2.6.0
# System
┌─────────────────────────┐
| OS | MacOS |
| Version | 12.2.1 |
| ID | 21D62 |
| Go Version | go1.21.3 |
| Platform | darwin |
| Architecture | amd64 |
└─────────────────────────┘
# Dependencies
┌────────────────────────────────────────────────────────────────────────┐
| Dependency | Package Name | Status | Version |
| Xcode command line tools | N/A | Installed | 2392 |
| Nodejs | N/A | Installed | 21.0.0 |
| npm | N/A | Installed | 10.2.0 |
| *Xcode | N/A | Installed | 13.2.1 (13C100) |
| *upx | N/A | Available | |
| *nsis | N/A | Available | |
└─────────────────────── * - Optional Dependency ────────────────────────┘
### Additional context
Any suggestions would be most appreciated.
I found a solution. It is a symbol conflict between wails and the github.com/energye/systray library.
As a workaround, I renamed AppDelegate to ApDelegate in github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/darwin/ AppDelegate.h, AppDelegate.m, Application.m
That fixed it temporarily at least until a refresh of the modules.
Given how central that concept is to your naming, I am not the one to suggest a longer-term fix. Did you have this problem with V3 yet?
Is there any chance you can make that small change at your end?
Thanks
We don't have that problem because we don't use 3rd party libraries for systray 😅
I found a solution. It is a symbol conflict between wails and the github.com/energye/systray library.
As a workaround, I renamed AppDelegate to ApDelegate in
github.com/wailsapp/wails/[email protected]/internal/frontend/desktop/darwin/ AppDelegate.h, AppDelegate.m, Application.mThat fixed it temporarily at least until a refresh of the modules.
Given how central that concept is to your naming, I am not the one to suggest a longer-term fix. Did you have this problem with V3 yet?
Is there any chance you can make that small change at your end?
Thanks
@precisionpete Does it run though? I tried to do the same based on your description. It builds but I get a panic on startup ` *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!' *** First throw call stack:
0 CoreFoundation 0x00007ff81b88018a __exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff81b3a642b objc_exception_throw + 48 2 CoreFoundation 0x00007ff81b8a82f6 -[NSException raise] + 9 3 AppKit 0x00007ff81e8c21fe -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 307 4 AppKit 0x00007ff81e8ae714 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1227 5 AppKit 0x00007ff81e8ae242 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42 6 AppKit 0x00007ff81f058e7c -[NSStatusBarWindow initForStatusItem:] + 88 7 AppKit 0x00007ff81f05bda1 -[NSStatusItem _initWithStatusBar:length:priority:systemInsertOrder:] + 349 8 AppKit 0x00007ff81eb18ac8 -[NSStatusBar _statusItemWithLength:withPriority:] + 76 9 myappmini 0x0000000100e21e64 -[AppDelegate applicationDidFinishLaunching:] + 100 10 myappmini 0x0000000100e23128 nativeStart + 248 11 myappmini 0x0000000100e21a19 _cgo_423650e18c01_Cfunc_nativeStart + 25 12 myappmini 0x0000000100077b28 runtime.asmcgocall.abi0 + 104 ) libc++abi: terminating due to uncaught exception of type NSException SIGABRT: abort PC=0x7ff81b6f51f2 m=4 sigcode=0 signal arrived during cgo execution `
It works for me. As long as I don't refresh the package. Otherwise, I will have to make the change again.
My procedure was:
- read the log and find the name of the symbol that conflicts
- in one of the packages (wails or the one that conflicts), grep all the code in that package and find the symbol that conflicts.
- rename the definition and uses of the symbol to something similar.
I made no effort to understand what the code was doing. I just wanted to give the offending symbol a different name.
After that, it worked. Maybe you changed too much? Re-get the package you modified and try again...
I'm sure there is a more permanent fix - like fork it and use a copy that does not update. But this was easy enough for me.
@precisionpete can you provide a basic example? I am on mac13 with the following code and it doesnt run; are you sure you didnt have to do anything related to using primary dispatchqueue?
func main() {
trayStart, trayStop := systray.RunWithExternalLoop(onReady, onExit)
// Create an instance of the app structure
app := NewApp()
// Create application with options
err := wails.Run(&options.App{
Title: "test",
Width: 780,
Height: 790,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
OnStartup: func(ctx context.Context) {
app.startup(ctx)
trayStart()
},
OnShutdown: func(ctx context.Context) {
trayStop()
app.shutdown(ctx)
},
Mac: &mac.Options{
About: &mac.AboutInfo{
Title: "test",
Message: "test",
Icon: icon1,
},
},
})
}
func onReady() {
systray.SetIcon(icon.Data)
systray.SetTitle("Awesome App")
systray.SetTooltip("Pretty awesome")
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
mQuit.SetIcon(icon.Data)
}
func onExit() {
}
FYI I managed to get this to work by forking branch of systray and
- renaming AppDelegate to SysTrayAppDelegate for all instances found in the fork project to get rid of the conflict. This lets you build. However I was using wails +macOS so I also needed to
- change the forked systray_darwin.m and protect ui code with dispatch_async(dispatch_get_main_queue(), ^{ // do work here }); Edit: obviously I am using the systray.RunWithExternalLoop() api in my wails app. Still testing but so far so good on mac
The renaming technique seems to be working quite reliably. I load my other package that conflicts (it's smaller), and do a global search and replace "AppDelegate" to "ApDelegate". Then I make that package read-only. Works every time.