systray icon indicating copy to clipboard operation
systray copied to clipboard

Duplicate symbol building on macOS

Open acastruc opened this issue 2 years ago • 5 comments

Building with wailsv2 on mac (11) I get this error

/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
duplicate symbol '_OBJC_CLASS_$_AppDelegate' in:
    /var/folders/hn/kchz9fwn4vxbg42s6yb3d8082p9k3x/T/go-link-109134485/000003.o
    /var/folders/hn/kchz9fwn4vxbg42s6yb3d8082p9k3x/T/go-link-109134485/000026.o
duplicate symbol '_OBJC_METACLASS_$_AppDelegate' in:
    /var/folders/hn/kchz9fwn4vxbg42s6yb3d8082p9k3x/T/go-link-109134485/000003.o
    /var/folders/hn/kchz9fwn4vxbg42s6yb3d8082p9k3x/T/go-link-109134485/000026.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Anyone seen this before? fwiw here are my build flags

INFO  Build command: go build -gcflags "all=-N -l" -tags dev,devtools -o bin/myapp-dev-darwin-amd64
OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES GO111MODULE=on TERMINAL_EMULATOR=JetBrains-JediTerm _INTELLIJ_FORCE_SET_GOROOT=/usr/local/go __CFBundleIdentifier=com.jetbrains.goland  XPC_FLAGS=0x0  GOROOT=/usr/local/go CGO_CFLAGS=-mmacosx-version-min=10.13 CGO_ENABLED=1 CGO_LDFLAGS=-framework UniformTypeIdentifiers -mmacosx-version-min=10.13 GOOS=darwin GOARCH=amd64)

acastruc avatar Oct 06 '23 05:10 acastruc

It might be helpful to try building without lots of extra parameters in case it cleans things up - though I doubt it will.

It may relate to how you are setting up the runloop as the app delegate controls application launch. Mixing GUI libraries can be problematic so you will likely need to share your setup code as well. In concept this can be done, however, as this systray project runs alongside Fyne and others well.

andydotxyz avatar Oct 06 '23 07:10 andydotxyz

Im wondering if CGO_CFLAGS=-mmacosx-version-min=10.13 CGO_ENABLED=1 CGO_LDFLAGS=-framework UniformTypeIdentifiers -mmacosx-version-min=10.13 is the culprit. I need to see if I can set mmacosx-version-min to something higher

acastruc avatar Oct 06 '23 15:10 acastruc

FYI I managed to get this to work by forking branch of systray and

  1. 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
  2. change systray_darwin.m and protect ui code with
dispatch_async(dispatch_get_main_queue(), ^{
   // do UI work here
});

acastruc avatar Jan 01 '24 21:01 acastruc

Ah! I guess wails also has an Objective-C class named "AppDelegate" then?

andydotxyz avatar Jan 03 '24 15:01 andydotxyz

Correct. That was the easier of the changes ;)

acastruc avatar Jan 03 '24 15:01 acastruc

I thought this was an issue with Xcode 15, I see it across all my Go projects.

anacrolix avatar Jun 28 '24 01:06 anacrolix

All your Go projects? if the only graphical dependency you have is the systray (and Fyne?) it should not be a problem. Or does every one of your Go projects also include wails?

andydotxyz avatar Jun 28 '24 09:06 andydotxyz

Projects linking through cgo.

anacrolix avatar Jun 28 '24 13:06 anacrolix

I think perhaps you are referring to a different duplicate symbol than the OP.

andydotxyz avatar Jun 28 '24 20:06 andydotxyz

Yes, I'm referring to this general problem: https://github.com/golang/go/issues/61229#issuecomment-1988965927. However those are warnings, and I see OP has errors.

anacrolix avatar Jun 29 '24 06:06 anacrolix

Yes, I'm referring to this general problem: golang/go#61229 (comment). However those are warnings, and I see OP has errors.

As you can see from the main entry of this issue the reported problem is that Systray uses the fairly generic AppDelegate class name:

duplicate symbol 'OBJC_CLASS$_AppDelegate' in:

andydotxyz avatar Jun 29 '24 21:06 andydotxyz