const-void / DOOM-fire-zig

DOOM's fire algo, in zig, for 256 color terminals w/no dependencies
71 stars 14 forks source link

Build issue on Ubuntu #14

Open mikemadden42 opened 2 weeks ago

mikemadden42 commented 2 weeks ago

Does anyone else see this build issue on Ubuntu?

$ zig build
...
...
+- install DOOM-fire
   +- zig build-exe DOOM-fire Debug native 1 errors
/home/hulk/opt/zig-linux-x86_64-0.13.0/lib/std/c.zig:1677:12: error: dependency on libc must be explicitly specified in the build command
error: the following command failed with 1 compilation errors:
/home/hulk/opt/zig-linux-x86_64-0.13.0/zig build-exe -ODebug -Mroot=/home/hulk/src/DOOM-fire-zig/src/main.zig --cache-dir /home/hulk/src/DOOM-fire-zig/.zig-cache --global-cache-dir /home/hulk/.cache/zig --name DOOM-fire --listen=-
Build Summary: 0/3 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
+- install DOOM-fire transitive failure
   +- zig build-exe DOOM-fire Debug native 1 errors
error: the following build command failed with exit code 1:
/home/hulk/src/DOOM-fire-zig/.zig-cache/o/465c6d43a52f00a87203cf9a087d4a87/build /home/hulk/opt/zig-linux-x86_64-0.13.0/zig /home/hulk/src/DOOM-fire-zig /home/hulk/src/DOOM-fire-zig/.zig-cache /home/hulk/.cache/zig --seed 0xa793b191 -Zc2b19a024407fa82
$ zig version
0.13.0
$ lsb_release -sir
Ubuntu
22.04
sweetbbak commented 1 week ago

you have to add exe.linkLibC(); to the build.zig file, but it also adds a segfault

thread 1670123 panic: index out of bounds: index 51135, len 6552
/home/sweet/repos/DOOM-fire-zig/src/main.zig:623:39: 0x103e193 in showDoomFire (DOOM-fire)
                spread_px = screen_buf[doFire_idx];
                                      ^
/home/sweet/repos/DOOM-fire-zig/src/main.zig:695:17: 0x103b5e9 in main (DOOM-fire)
    showDoomFire();
                ^
/usr/lib/zig/std/start.zig:524:37: 0x103b0fe in main (DOOM-fire)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x71a86cc38e07 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x71a86cc38e07` was not available, trace may be incomplete

???:?:?: 0x71a86cc38ecb in ??? (libc.so.6)
???:?:?: 0x103ad44 in ??? (???)
zsh: IOT instruction (core dumped)  ./zig-out/bin/DOOM-fire
const-void commented 6 days ago

Thanks for reporting! I will do some sleuthing.

mikemadden42 commented 4 days ago

Thanks @const-void . The follow diff fixes the build issues I hit on Ubuntu. I'm not sure if this also works on macOS & other supported platforms.

index 2c1639c..29ece06 100644
--- a/build.zig
+++ b/build.zig
@@ -22,6 +22,8 @@ pub fn build(b: *std.Build) void {
         .optimize = optimize,
     });

+    exe.linkLibC();
+
     // This declares intent for the executable to be installed into the
     // standard location when the user invokes the "install" step (the default
     // step when running `zig build`).
diff --git a/src/main.zig b/src/main.zig
index b2864e3..167136b 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -5,6 +5,7 @@
 //
 const builtin = @import("builtin");
 const std = @import("std");
+const libc = @import("libc");

 const allocator = std.heap.page_allocator;