#Problems C standard library when building a raylib project for wasm32-emscripten

1 messages · Page 1 of 1 (latest)

lucid sable
#

I use the command zig build -Dtarget=wasm32-emscripten --sysroot emsdk/upstream/emscripten but I get errors such as

install
└─ install particle-sim
   └─ zig build-exe particle-sim Debug wasm32-emscripten
      └─ zig build-lib raylib Debug wasm32-emscripten 8 errors
/home/gaffclant/.cache/zig/p/1220aa75240ee6459499456ef520ab7e8bddffaed8a5055441da457b198fc4e92b26/src/utils.c:47:10: 
error: 'stdlib.h' file not found

I added exe.linkLibC(); to my build.zig to no success.

robust finch
#

Can you show your build.zig?

lucid sable
#
const std = @import("std");

pub fn build(b: *std.Build) void {
    const target = b.standardTargetOptions(.{});

    const optimize = b.standardOptimizeOption(.{});

    const exe = b.addExecutable(.{
        .name = "particle-sim",
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });
    exe.linkLibC();
    const raylib_dep = b.dependency("raylib-zig", .{
        .target = target,
        .optimize = optimize,
    });
    const raylib = raylib_dep.module("raylib"); // main raylib module
    const raygui = raylib_dep.module("raygui"); // raygui module
    const raylib_artifact = raylib_dep.artifact("raylib"); // raylib C library
    exe.linkLibrary(raylib_artifact);
    exe.root_module.addImport("raylib", raylib);
    exe.root_module.addImport("raygui", raygui);

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);

    run_cmd.step.dependOn(b.getInstallStep());

    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

    const exe_unit_tests = b.addTest(.{
        .root_source_file = b.path("src/main.zig"),
        .target = target,
        .optimize = optimize,
    });

    const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);

    const test_step = b.step("test", "Run unit tests");
    test_step.dependOn(&run_exe_unit_tests.step);
}
robust finch
#

Maybe you need to raylib_artifact.linkLibC() ?

lucid sable
#

same error still ._.

robust finch
#

And on both modules?

lucid sable
#
raylib_artifact.linkLibC();
exe.linkLibC();
exe.linkLibrary(raylib_artifact);

yep

robust finch
#

I meant raylib and raygui

lucid sable
#

how would i tell the raylib module to link libc? is it raylib.link_libc = true;?

robust finch
#

Yep!

lucid sable
#

same error grief