#Cross-Compiling From Windows

1 messages · Page 1 of 1 (latest)

warm gate
#

I've tried a lot of different options and have done a lot of research but I'm really lost on how this is supposed to work.

What I have:

  • C/C++ Game that uses openssl, glew, and sdl2
  • My build.zig works perfectly when built natively on windows, linux86_64, and mac86_64
  • the 3 dependencies are pulled from apt and homebrew and are prebuilt dlls on windows

What I'd like to do:

  • Cross-compile executables for the above 3 platforms all from my windows environment
  • Be able to add new targets I don't have native access to like aarch64-macos

Where I'm having trouble:
First test was just -Dtarget=x86_64-linux-gnu. First thing is missing the dependencies, so I copied them out of my debian install
Now SDL needs headers for X11. ok, copied those out as well.
Now SDL gets linker errors...... why? I would expect SDL2 to manage all of its own dependencies and not pass them onto my exe.
Now on windows I explicitly link to windows OS libraries like kernel32, user32, etc... is thie missing bit here needing those from my debian install too? I tried copying some over like X11.so and Xext.so but still getting several unresolved.
Is there a primer for full list of things I need to link my exe to so satisfy SDL'2 dependencies?

I feel like I'm getting close but just missing some of the final steps to getting this working right.

THeoretically I'd like to have these built in CI at some point which wouldnt even necessarily need to be a windows machine

supple hare
warm gate
#

aaaah see i didnt know about WSL >_> that definitely helps, I take it I can install that and point my build.zig at it

#

for mac i think i can download the macOS SDK's so maybe there's a path there

warm gate
#

hmmm, strange, pointed to WSL:

        if(!target.isNativeOs()){
            exe.addIncludePath(.{ .path = "//wsl.localhost/Ubuntu/usr/include/" });
            exe.addIncludePath(.{ .path = "//wsl.localhost/Ubuntu/usr/include/x86_64-linux-gnu/" });

            exe.addIncludePath(.{ .path = "//wsl.localhost/Ubuntu/usr/include/SDL2/" });
            exe.addIncludePath(.{ .path = "//wsl.localhost/Ubuntu/usr/include/x86_64-linux-gnu/SDL2/" });

            exe.addLibraryPath(.{ .path = "//wsl.localhost/Ubuntu/usr/lib/x86_64-linux-gnu/" });
        }

        exe.linkSystemLibrary("SDL2");
        exe.linkSystemLibrary("crypto");
        exe.linkSystemLibrary("ssl");
        exe.linkSystemLibrary("GLEW");
        exe.linkSystemLibrary("OpenGL");

But getting this when building, no further error info

$ zig build -Dtarget=x86_64-linux-gnu
zig build-exe chron4 Debug x86_64-linux-gnu: error: warning: Unexpected: \\wsl.localhost\Ubuntu\usr\lib\x86_64-linux-gnu\libSDL2.so
error: Unexpected
cosmic dragon
teal hollow
cosmic dragon
teal hollow
warm gate
#

Yeah I've been going back and forth on it, that was the original goal because that's how gamedev usually does things on Windows, but I've been having a ton of struggle with it.

If I went back and tried again with SDL with what I know now I might get further, but then there's SSL which there's a great zig for but it only builds in 0.11, so might have to PR an upgrade for that, just feels like a pain

So I've been going the package manager route, which hey at least I got them building natively on there!

warm gate
#

ok successfully build an executable on windows for linux.... copied it over to WSL and tried to run it, got permission denied, added chmod +x, now saying file not found, what am i missing there

#

ah looks like it built with linux-musl isntead of gnu

#

hmm, trying to zig build with linux-gnu fails with missing symbols _isoc23_stroll

#

seems like maybe zig's trying to use musl instead of glibc?

warm gate
warm gate
#

oooookay so installing gcc on WSL fixed it, which i guess means the windows cross-compile folder needs the CRT?

#

kind of confused because zig should theoretically have that?

#

__isoc23_strtoul is defined in libc/glibc/include, wonder if its just about manually pointing the build to glibc 😐

warm gate
#

so now ive copied the sys include folder that shows up in zig libc into my cross compile directory, and added exe.addSystemIncludePath(sysInclude); but still same error, seems to be something there, maybe another flag in the build or something

warm gate
warm gate
#

mmmmk still the same error BUT, doing linux-gnu.2.38 did compile correctly so like is stated in that PR it's a version issue, maybe i still dont have the binary with this fix, idk how often the one on the website updates from pushes to master

warm gate
#

I think this all makes sense now, the update to 2.38 made targeting lower versions fail, can't seem to get zig building in Windows so I guess I'll just wait for the latest release to end up on the download page and confirm that it fixes it