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

Raygui can't be used when raylib is built as a shared library #147

Closed
MassKlaus opened this issue Sep 9, 2024 · 7 comments
Closed

Raygui can't be used when raylib is built as a shared library #147

MassKlaus opened this issue Sep 9, 2024 · 7 comments

Comments

@MassKlaus
Copy link

MassKlaus commented Sep 9, 2024

Error:

lld-link: undefined symbol: GuiPanel

Adding the .shared = true when using raygui breaks things

buid.zig:

const raylib_dep = b.dependency("raylib-zig", .{ .target = target, .optimize = optimize, .shared = true });

main.zig

const rg = @import("raygui");
const rl = @import("raylib");

pub fn main() anyerror!void {
    // Initialization
    //--------------------------------------------------------------------------------------
    const screenWidth = 800;
    const screenHeight = 450;

    rl.initWindow(screenWidth, screenHeight, "raylib-zig [core] example - basic window");
    defer rl.closeWindow(); // Close window and OpenGL context

    rl.setTargetFPS(60); // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------

    // Main game loop
    while (!rl.windowShouldClose()) { // Detect window close button or ESC key
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        rl.beginDrawing();
        defer rl.endDrawing();

        rl.clearBackground(rl.Color.white);

        const bounds = rl.Rectangle.init(50, 50, 100, 400);

        _ = rg.guiPanel(bounds, "Something");

        rl.drawText("Congrats! You created your first window!", 190, 200, 20, rl.Color.light_gray);
        //----------------------------------------------------------------------------------
    }
}

Main reason for trying to build raylib and raygui as a shared library is implementing hot reloading eventually

@ZackeryRSmith
Copy link
Contributor

ZackeryRSmith commented Sep 9, 2024

Hey @MassKlaus, have you made sure to add the raygui import in the build.zig? I copied your main file 1:1, but here is my build file (minus the web export code).

const std = @import("std");
const rlz = @import("raylib-zig");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});
    
    const raylib_dep = b.dependency("raylib-zig", .{
        .target = target,
        .optimize = optimize,
	.shared = true,
    });

    const raylib = raylib_dep.module("raylib");
    const raygui = raylib_dep.module("raygui");  // note this line
    const raylib_artifact = raylib_dep.artifact("raylib");

    const exe = b.addExecutable(.{ .name = "shared_gui", .root_source_file = b.path("src/main.zig"), .optimize = optimize, .target = target });

    exe.linkLibrary(raylib_artifact);
    exe.root_module.addImport("raylib", raylib);
    exe.root_module.addImport("raygui", raygui); // note this line

    const run_cmd = b.addRunArtifact(exe);
    const run_step = b.step("run", "Run shared_gui");
    run_step.dependOn(&run_cmd.step);

    b.installArtifact(exe);
}

Using Zig 0.13 and the latest version of these bindings, everything builds fine. Here is the result:

Screenshot 2024-09-09 at 6 17 12 PM

@Not-Nik
Copy link
Owner

Not-Nik commented Sep 10, 2024

raygui is added to the build regardless of configuration, just like any other raylib source file. As @ZackeryRSmith said, this is probably a build misconfig on your end.

@MassKlaus
Copy link
Author

Sorry for the late reply but yeah, I forgot to include my full build script but it was the default zig-init build script with the raylib-zig bindings imports for both raylib and raygui. I copied your build script and still ran into the same issue. I am on windows, so maybe a compiler thing?

@ZackeryRSmith
Copy link
Contributor

ZackeryRSmith commented Sep 11, 2024

I am on windows, so maybe a compiler thing?

It is strange that this only occurs when building as a shared library. I don't think it's an issue with building on Windows. However if that is the case: the issue is likely with Raylib's build.zig and is a separate issue unrelated to this project.

I cannot reproduce this error on my machine sadly, so it's hard for me to debug. Although I'm a bit lost here... To be clear though: What version of Zig are you using and how are you installing the bindings.

Main reason for trying to build raylib and raygui as a shared library is implementing hot reloading eventually

I guess for the moment just ignore building as a shared library. Once I have the chance I will try debugging this on my Windows VM.

@MassKlaus
Copy link
Author

I am using Zig 0.13.0 and the bindings are fetched as indicated in the ReadMe of the project. I've just reinstalled my system so I'll a chance later and test in wsl 2 when I can.

A lot of thanks!

@Not-Nik
Copy link
Owner

Not-Nik commented Oct 13, 2024

Any updates? Otherwise I'll close this, since it seems resolved and I can't repro it on my machine.

@MassKlaus
Copy link
Author

I wasn't really able to figure out what was happening sadly, wsl doesn't have x11 and couldn't push for more so for now it's best to close till someone else has some similar issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants