Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Fail to build imguidemo.go with cimgui-go - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here #762

Closed
Challanger524 opened this issue Feb 15, 2024 · 14 comments
Labels
bug Something isn't working

Comments

@Challanger524
Copy link

Challanger524 commented Feb 15, 2024

What happend?

Fail to build giu/imguidemo.go, even after go clean -cache

Code example

main.go
package main

import (
	сimgui "github.com/AllenDang/cimgui-go"
	g "github.com/AllenDang/giu"
)

func main() {
	wnd := g.NewMasterWindow("ImGui widgets demo", 640, 480, 0)
	wnd.Run(loop)
}

func loop() {
	сimgui.ShowDemoWindow()
}
go.mod
module bplan

go 1.22.0

require (
	github.com/AllenDang/cimgui-go v0.0.0-20240214101732-0ab265480437
	github.com/AllenDang/giu v0.7.0
)

require (
	github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 // indirect
	github.com/AllenDang/imgui-go v1.12.1-0.20221124025851-59b862ca5a0c // indirect
	github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // indirect
	github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
	github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
	github.com/mazznoer/csscolorparser v0.1.3 // indirect
	github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64 // indirect
	github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
	github.com/sahilm/fuzzy v0.1.0 // indirect
	golang.org/x/image v0.12.0 // indirect
	golang.org/x/sys v0.5.0 // indirect
	gopkg.in/eapache/queue.v1 v1.1.0 // indirect
)

build output
...
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/lib/windows/x64\cimgui.a(imgui_widgets.cpp.obj):imgui_widgets.:(.text+0x28cf0): multiple definition of `ImGui::SliderInt2(char const*, int*, int, int, char const*, int)'; C:\Users\Daniil\AppData\Local\Temp\go-link-4229020252\000089.o:C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/imgui_widgets.cpp:3024: first defined here
...
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/lib/windows/x64\cimgui.a(implot_items.cpp.obj):implot_items.c:(.rdata+0xcb0): multiple definition of `ImPlot::MaxIdx<unsigned int>::Value'; C:\Users\Daniil\AppData\Local\Temp\go-link-4229020252\000095.o:C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/implot_items.cpp:699: first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/lib/windows/x64\cimgui.a(implot_items.cpp.obj):implot_items.c:(.rdata+0xcb4): multiple definition of `ImPlot::MaxIdx<unsigned short>::Value'; C:\Users\Daniil\AppData\Local\Temp\go-link-4229020252\000095.o:C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/implot_items.cpp:698: first defined here
collect2.exe: error: ld returned 1 exit status

To Reproduce

go build -v -x -gcflags='all=-N -l' -ldflags '-extldflags=-static' ./cmd/bplan/
Context: testing in my own project, no other .go source files` present

...
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/lib/windows/x64\cimgui.a(imgui_widgets.cpp.obj):imgui_widgets.:(.text+0x28cf0): multiple definition of `ImGui::SliderInt2(char const*, int*, int, int, char const*, int)'; C:\Users\Daniil\AppData\Local\Temp\go-link-1062457848\000089.o:C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/imgui_widgets.cpp:3024: first defined here
...
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/lib/windows/x64\cimgui.a(implot_items.cpp.obj):implot_items.c:(.rdata+0xcb0): multiple definition of `ImPlot::MaxIdx<unsigned int>::Value'; C:\Users\Daniil\AppData\Local\Temp\go-link-2178425106\000095.o:C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/implot_items.cpp:699: first defined here
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/lib/windows/x64\cimgui.a(implot_items.cpp.obj):implot_items.c:(.rdata+0xcb4): multiple definition of `ImPlot::MaxIdx<unsigned short>::Value'; C:\Users\Daniil\AppData\Local\Temp\go-link-2178425106\000095.o:C:/Users/Daniil/go/pkg/mod/github.com/!allen!dang/[email protected]/implot_items.cpp:698: first defined here
collect2.exe: error: ld returned 1 exit status

Looks like imgui-go conflicting with cimgui-go, is it possible to put these lizards in one jar as in example?
It was changed in "migration commit" here:

+	"github.com/AllenDang/cimgui-go"
	g "github.com/AllenDang/giu"
-	"github.com/AllenDang/imgui-go"

Before gofmt automatically assigned imgui namespace to imgui-go library and it was building fine (after feeding bool param to ShowDemo func), but after manual change to cimgui-go it broke :(

Version

master

OS

Windows 10

@Challanger524 Challanger524 added the bug Something isn't working label Feb 15, 2024
@Challanger524 Challanger524 changed the title [bug] cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here [bug] Fail to build giu/imguidemo.go - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here Feb 15, 2024
@Challanger524 Challanger524 changed the title [bug] Fail to build giu/imguidemo.go - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here [bug] Fail to build **giu/imguidemo.go** - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here Feb 15, 2024
@Challanger524 Challanger524 changed the title [bug] Fail to build **giu/imguidemo.go** - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here [bug] Fail to build giu/imguidemo.go - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here Feb 15, 2024
@Challanger524 Challanger524 changed the title [bug] Fail to build giu/imguidemo.go - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here [bug] Fail to build imguidemo.go with cimgui-go - cimgui.a:*.c: multiple definition of <func>; <go_path>/pkg/mod/github.com/!allen!dang/imgui-go@<ver>/*.cpp: first defined here Feb 15, 2024
@Challanger524
Copy link
Author

Is it possible to resolve conflict through -ldflags for conflicting package?

@Challanger524
Copy link
Author

Challanger524 commented Feb 15, 2024

Helped adding -extldflags=-Wl,-allow-multiple-definition
full: go build -v -x -gcflags='all=-N -l' -ldflags='-extldflags=-Wl,-static,-allow-multiple-definition' ./cmd/bplan/

How much threat does this posses to the giu universe?🤭

@gucio321

This comment was marked as outdated.

@gucio321
Copy link
Collaborator

gucio321 commented Feb 15, 2024

ok I've just read your comment, its useful sometimes 😄

So, my answer is similar:
You should not put imgui-go and cimgui-go in the same project as it might lead to some unexpected behaviours.
Its because imgui-go uses different Dear ImGui version.

If you don't want to migrate your project ot cimgui-go (this shouldn't be hard to do) you could theoritically fork this repo and generate it for older Dear ImGui (this from imgui-go).
This should work

@Challanger524

This comment was marked as outdated.

@Challanger524
Copy link
Author

Now I get it! Your hidden comment is the most valuable one :)

check if your giu uses cimgui-go (ensure you're using giu's master and not v0.7)

exactly!
go get https://github.com/AllenDang/giu loaded v0.7 that depends on imgui-go while master is migrated to cimgui-go with it's examples.

Thank You @gucio321! Did not expected such a surprise from go get that it gives higher priority to tag <version> rather then master branch, which is always on top on GitHub.

How to Upgrade and Downgrade Dependencies

go get foo updates to the latest version of foo. go get foo is equivalent to go get foo@latest — in other words, @latest is the default if no @ version is specified.

In this section, “latest” is the latest version with a semver tag, or the latest known commit if there are no semver tags. Prerelease tags are not selected as “latest” unless there are no other semver tags on the repository (details).

@Challanger524
Copy link
Author

☝️

@Challanger524
Copy link
Author

nope, master giu branch throws exception on clean (almost empty) main.go file
Probably @master is not yet ready for release

Exception has occurred: fatal error
Error getting throw reason: could not find symbol value for s
Stack:
	0  0x00007ff623ea6e24 in runtime.winthrow
	    at C:/Program Files/Go/src/runtime/signal_windows.go:349
	1  0x00007ff623ea6e07 in runtime.lastcontinuehandler
	    at C:/Program Files/Go/src/runtime/signal_windows.go:342
	2  0x00007ff623ea69f3 in runtime.sigtrampgo
	    at C:/Program Files/Go/src/runtime/signal_windows.go:177
	3  0x00007ff6241555b0 in ???
	    at ?:-1
	    error: Only part of a ReadProcessMemory or WriteProcessMemory request was completed.
	(truncated)

main.go

package main

import (
	"fmt"
	"github.com/AllenDang/giu"
)


func main() {
	fmt.Println("Hello World! by: giu")
	wnd = giu.NewMasterWindow("ImGui widgets demo", 800, 600, 0)
	wnd.Run(loop)
}

func loop() {
	fmt.Print("+")
}

go.mod

module giu.master

go 1.22.0

require github.com/AllenDang/giu v0.7.1-0.20240214102145-b906c79ac41f

require (
	github.com/AllenDang/cimgui-go v0.0.0-20231219093052-24bd5dc22643 // indirect
	github.com/AllenDang/go-findfont v0.0.0-20200702051237-9f180485aeb8 // indirect
	github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3 // indirect
	github.com/mazznoer/csscolorparser v0.1.3 // indirect
	github.com/napsy/go-css v0.0.0-20221107082635-4ed403047a64 // indirect
	github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
	github.com/sahilm/fuzzy v0.1.0 // indirect
	golang.design/x/hotkey v0.4.1 // indirect
	golang.design/x/mainthread v0.3.0 // indirect
	golang.org/x/image v0.15.0 // indirect
	golang.org/x/sys v0.5.0 // indirect
	gopkg.in/eapache/queue.v1 v1.1.0 // indirect
)

@gucio321
Copy link
Collaborator

thats the problem.. your code works for me...
Could you try to debug it somehow?

@Challanger524
Copy link
Author

your code works for me...

on Windows 10?

@gucio321
Copy link
Collaborator

On fedora linux

@Challanger524
Copy link
Author

Before major version release it going to be tested on shWindows anyway (yes?), so if this is a case - we are prepared mentally. Or I just boiled it in the wrong way 🤷 somehow.

Not in a hurry for the solution, was playing with golang and imgui binding. Now I'm ready to go back to good old c++ with native imgui 😮‍💨

@gucio321
Copy link
Collaborator

well, you can always use working version with imgui-go.
In case of cimgui-go and windows: well I'm the only periodically active developer here right now. Whats more Im not really familiar with windows - my native dev-env is linux. I heard that cimgui sometimes crashes on windows but I can't debug this unfortunately. As long as there is no one to help, I don't know what can I do 😢

@gucio321
Copy link
Collaborator

also, here is an issue for this: #735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants