AllenDang / cimgui-go

Auto generated Go wrapper for Dear ImGui via cimgui
MIT License
338 stars 53 forks source link

dxguid & dxerr8 Prevent Cross-Compile on Linux Targeting Windows #291

Closed xEricL closed 2 weeks ago

xEricL commented 2 months ago

I am cross compiling an app with Zig (v0.11.0) on Ubuntu 22.04 to be used on Windows. It appears the two libraries dxguid & dxerr8 cannot be found. Is there a way around this?

Here is the error:

/opt/hostedtoolcache/go/1.22.5/x64/pkg/tool/linux_amd64/link: running zig failed: exit status 1
error: unable to find Dynamic system library 'dxguid' using strategy 'paths_first'. searched paths:
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxguid.dll
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxguid.lib
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/libdxguid.a
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxguid.dll
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxguid.lib
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/libdxguid.a
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxguid.dll
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxguid.lib
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/libdxguid.a
error: unable to find Dynamic system library 'dxerr8' using strategy 'paths_first'. searched paths:
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxerr8.dll
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxerr8.lib
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/libdxerr8.a
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxerr8.dll
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxerr8.lib
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/libdxerr8.a
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxerr8.dll
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/dxerr8.lib
  /home/runner/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-2024071[105](https://github.com/alpine-client/pinnacle/actions/runs/10071331690/job/27841297791#step:12:106)5741-4b4d3ac1ee30/lib/windows/x64/libdxerr8.a

Here is the full log from the GitHub actions workflow where I've been trying to do this.

Here is the workflow file if that helps at all.

Notes: There is a chance this is caused by an issue fixed in Zig 0.12.0. However, when I try using Zig v0.12.0+ to compile my app, Zig can't see that cimgui.a, libglfw3.a, and libSDL2.a are located in /lib/windows/x64/. (Maybe because of this issue?) My C knowledge is very limited, so I can't say for certain. I was hoping you guys could look into this and let me know if this is an issue with Zig or cimgui-go.

Any help would be greatly appreciated.

AllenDang commented 2 months ago

I know nothing about zig so I might not be able to help here.

gucio321 commented 2 months ago

@xEricL its also my first time when I hear about zig.

I think you need to care about some type of PATH or INCLUDE_PATH in zig, however it works. generally, in cimgui.go file is a list of C/C++/Linker flags that your compiler needs to read and use. You can try to copy-paste them in your command line and check - it may work...

xEricL commented 2 months ago

The weird thing is that my cross-compiling worked when my app was using Giu v0.7 but when I upgraded to Giu v0.8 + cimgui it broke, so I was thinking it was because of a difference in cimgui (which is why I created the issue in this repo).

I will continue researching and keep you guys updated here. A lot of developers use Zig for cross compiling CGO, so I'm sure I won't be the last to run into this problem.

xEricL commented 2 months ago

@gucio321 Is there a reason cimgui.a in /lib/windows/x64/ isn't following the naming convention for libraries? Like how glfw3 is called libglfw3.a and SDL2 is called libSDL2.a? I figured out how to get Zig to look in /lib folder but it keeps looking for libcimgui.a instead of cimgui.a.

| error: unable to find dynamic system library 'cimgui' using strategy 'paths_first'. searched paths:
|   /root/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/cimgui.dll
|   /root/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/cimgui.lib
|   /root/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64/libcimgui.a

This is my build command

env GOARCH=amd64 GOOS=windows \
CC="zig cc -target x86_64-windows-gnu -Wl,--subsystem,windows -Wl,-s" \
CXX="zig c++ -target x86_64-windows-gnu -Wl,--subsystem,windows -Wl,-s" \
CGO_CFLAGS="-I/root/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64" \
CGO_LDFLAGS="-L/root/go/pkg/mod/github.com/!allen!dang/cimgui-go@v0.0.0-20240711055741-4b4d3ac1ee30/lib/windows/x64 -lcimgui -lglfw3 -lSDL2" \
go build -trimpath -p 4 -ldflags="-H=windowsgui" -o bin/pinnacle-windows-amd64.exe .
gucio321 commented 2 months ago

But it isn't /lib its $PKGDIR/lib

These paths are set in cimgui.go file i think zig should read from there

https://github.com/AllenDang/cimgui-go/blob/main/cimgui.go#L7

It says it wants cimgui.a so why zig doesn't understand that...

gucio321 commented 2 months ago

Btw I undersrand meaning convention note and yeah, if this is a standard we should change to libcimgui

gucio321 commented 2 months ago

Are you sure you need to specify these LDFLAGS in your zig command?

xEricL commented 2 months ago

Are you sure you need to specify these LDFLAGS in your zig command?

I'm not 100% sure. Honestly I've just been trying everything to get it to work. The biggest issue is that dxguid and dxerr8 can't be found (like in the original post). Do you know where it should be finding that library?

xEricL commented 2 months ago

@gucio321 I just need to be able to cross-compile for Windows on Linux. Have you guys been able to do that after giu migrated to cimgui-go in v0.8?

gucio321 commented 2 months ago

dx* sounds like direcx library. What requires that ? I think cimgui-go uses glfw with opengl

gucio321 commented 2 months ago

in case of cross-compilation for windows: I used to do that with mingw:

CC="x86_64-w64-mingw32-gcc" CXX="x86_64-w64-mingw32-g++" GOOS="windows" GOARCH="amd64" CGO_ENABLED="1" go build -o widgets.exe .

This method iirc is described somewhere in giu docs.

gucio321 commented 2 months ago

here is a workflow using that method: https://github.com/gucio321/tic-tac-go/blob/master/.github/workflows/build.yml

xEricL commented 2 months ago

dx* sounds like direcx library. What requires that ? I think cimgui-go uses glfw with opengl

The only place it is mentioned is here. https://github.com/AllenDang/cimgui-go/blob/4b4d3ac1ee3063ee5ecdc89044b664b6d53dc5e1/sdl_backend.go#L6

gucio321 commented 3 weeks ago

@xEricL can we close this? I think that the original issue was fixed (mingw compilation works)?