Unable to use readline

I’m stuck on Stage #QP2, using Zig 0.15.1. The issue is that readline is not found in the Codecrafters environment, causing the build to fail when I type codecrafters test.

I’ve tried looking at similar issues faced by others, specifically:

  1. [#QP2][Zig] Using readline, huh?
  2. Builtin completion #qp2 [zig]

I did the steps listed in both of them but it is still not working for me. In #2, @andy1li mentioned about upgrading the buildpack of the repo. Is the same required here?

Here are my logs:

[build] Starting build...
[build] If you don't see logs for 60s+, please contact us at hello@codecrafters.io
[build] Step 1 complete.
[build] Step 2 complete.
[build] Step 3 complete.
[build] Step 4 complete.
[build] Step 5 complete.
[build] Step 6 complete.
[build] Step 7 complete.
[build] Step 8 complete.
[build] Step 9 complete.
[build] Step 11 complete.
[build] Step 12 complete.
[build] Step 13 complete.
[build] Step 14 complete.
[build] Step 15 complete.
[build] Step 16 complete.
[build] > install
[build] > +- install main
[build] >    +- compile exe main Debug native failure
[build] > error: error: unable to find dynamic system library 'readline' using strategy 'paths_first'. searched paths:
[build] >   /usr/local/lib/libreadline.so
[build] >   /usr/local/lib/libreadline.a
[build] >   /usr/lib/x86_64-linux-gnu/libreadline.so
[build] >   /usr/lib/x86_64-linux-gnu/libreadline.a
[build] >   /lib64/libreadline.so
[build] >   /lib64/libreadline.a
[build] >   /lib/libreadline.so
[build] >   /lib/libreadline.a
[build] >   /usr/lib64/libreadline.so
[build] >   /usr/lib64/libreadline.a
[build] >   /usr/lib/libreadline.so
[build] >   /usr/lib/libreadline.a
[build] >   /lib/x86_64-linux-gnu/libreadline.so
[build] >   /lib/x86_64-linux-gnu/libreadline.a
[build] > 
[build] > error: the following command exited with error code 1:
[build] > /usr/local/zig/zig build-exe -lreadline -Mroot=/app/src/main.zig -lc --cache-dir .zig-cache --global-cache-dir /root/.cache/zig --name main -
-zig-lib-dir /usr/local/zig/lib/ --listen=-
[build] > 
[build] > Build Summary: 0/3 steps succeeded; 1 failed
[build] > install transitive failure
[build] > +- install main transitive failure
[build] >    +- compile exe main Debug native failure
[build] > 
[build] > error: the following build command failed with exit code 1:
[build] > .zig-cache/o/2ba12b09f08bf543d72884e43aea60c5/build /usr/local/zig/zig /usr/local/zig/lib /app .zig-cache /root/.cache/zig --seed 0x2b76c53a 
-Z9bc2de046c80aa23
[build] Error: process "/bin/sh -c .codecrafters/compile.sh" did not complete successfully: exit code: 1.
[build] > error: the following command exited with error code 1:
[build] > /usr/local/zig/zig build-exe -lreadline -Mroot=/app/src/main.zig -lc --cache-dir .zig-cache --global-cache-dir /root/.cache/zig --name main -
-zig-lib-dir /usr/local/zig/lib/ --listen=-
[build] > 
[build] > Build Summary: 0/3 steps succeeded; 1 failed
[build] > install transitive failure
[build] > +- install main transitive failure
[build] >    +- compile exe main Debug native failure
[build] > 
[build] > error: the following build command failed with exit code 1:
[build] > .zig-cache/o/2ba12b09f08bf543d72884e43aea60c5/build /usr/local/zig/zig /usr/local/zig/lib /app .zig-cache /root/.cache/zig --seed 0x2b76c53a 
-Z9bc2de046c80aa23
[build] Build failed. Check the logs above for the reason.
[build] If you think this is a CodeCrafters error, please contact us at hello@codecrafters.io.

And here’s a snippet of my main.zig code:

...
const clib = @cImport({
    @cInclude("stdio.h");
    @cInclude("stdlib.h");
    @cInclude("string.h");
    @cInclude("readline/readline.h");
});
...

And build.zig:

...
    // Tried both ways, works in local but not in CC environment

    // exe.root_module.link_libc = true;
    // exe.root_module.linkSystemLibrary("readline", .{});

    exe.linkLibC();
    exe.linkSystemLibrary("readline");
...

Hey @adarsh-kishore786, we’ve just pushed a fix in this PR.

Let me know if you’re still seeing any issues.

Thanks @andy1li , I am able to submit successfully now

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.