Hi there,
I thought I had a basic but good enough understand of dlopen/LoadLibrary, rpath, LD_LIBRARY_PATH … Turns out I was very wrong: I have no idea what I’m doing.
I am trying to write a very small cross-platorm (macOS, Linux, Windows) sample to use OpenGL ES 3.0 through Google Angle with zig.
The repo is here: https://github.com/mpalomas/angle-gles.git
To achieve that I use native libraries: Google Angle (prebuilt binaries + headers), GLFW and Imgui with its OpenGL backend (both fully build in build.zig).
If you have time and run zig build run
you should at least see some logs about the OpenGL ES version, and a white window. And if you are on Windows, you will also see a basic imgui window.
And that’s my problem: despite my effort, I am struggling with OS differences regarding RPath and potentially even link time… Basically I can only get the imgui part to build and run on Windows. On Linux and MacOS, it triggers link errors related to all OpenGL functions used.
Meaning, if you are on Linux or MacOS, in the main.zig, you can comment the comptime if around line 109 so cImGui_ImplOpenGL3_InitEx gets called: it will no longer build, you will get link errors.
I am puzzled because in principle, imgui is supposed to use dlopen to load symbols for the OpenGL ES libs coming from Angle (deployed in bin alongside the exe). And it works on Windows ?!
GLFW also works this way, and since you can see the window and the logs, it definitely works. To make it work, I had to adjust rpath (see build.zig) but nothing fancy:
if (target.result.os.tag == .macos) {
exe_mod.addRPathSpecial("@executable_path/.");
} else if (target.result.os.tag == .linux) {
exe_mod.addRPathSpecial("$ORIGIN");
}
But for the imgui lib, I cannot get it to work. It seems like imgui is looking for the OpenGL symbols at link time but only on MacOS and Linux? I must have missed something, either in my build.zig, or a macro to define…
Since what I get are link errors, I actually tried to linkSystemLibrary to libGLESv2. And it solves my link errors… but then fail to run because it cannot find the lib! Despite my rpath adjusment.
Anyway, I am not asking you to spend time and debug for me, but instead:
- How would you debug this kind of link or runtime issue? Any guideline, advice?
- Maybe some zig compiler options to get more verbose details?
- Any cli tool I could use to analyze the binaries (check rpath…) ?
Thank you in advance!