# \[#QP2\]\[Zig\] Using readline, huh?

**URL:** https://forum.codecrafters.io/t/qp2-zig-using-readline-huh/8554
**Category:** Challenges
**Tags:** challenge:shell
**Created:** [April 10, 2025, 6:19pm UTC](https://forum.codecrafters.io/t/qp2-zig-using-readline-huh/8554 "2025-04-10T18:19:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![levitte](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/levitte/32/8971_2.png) [@levitte](https://forum.codecrafters.io/u/levitte)
#### Post date: [April 10, 2025, 6:19pm UTC](https://forum.codecrafters.io/t/qp2-zig-using-readline-huh/8554/1 "2025-04-10T18:19:09Z")

</div>

From the challenge:

> **Notes:**  
> We recommend using a library like [readline](https://en.wikipedia.org/wiki/GNU_Readline) for your implementation. Most modern shells and REPLs (like the Python REPL) use readline under the hood.

Cool, sounds good, and was a fun challenge, allowed me to learn how to interface Zig code with C functionality of that sort. And famous last words, “builds on my machine!”

Then I pushed to codecrafters, and my heart sank …

```auto
remote: [build] > install
remote: [build] > +- install main
remote: [build] > +- zig build-exe main Debug native failure
remote: [build] > error: error: unable to find dynamic system library 'readline' using strategy 'paths_first'. searched paths:
remote: [build] > /usr/local/lib/libreadline.so
remote: [build] > /usr/local/lib/libreadline.a
remote: [build] > /lib/libreadline.so
remote: [build] > /lib/libreadline.a
remote: [build] > /usr/lib/libreadline.so
remote: [build] > /usr/lib/libreadline.a
remote: [build] > 
remote: [build] > error: the following command exited with error code 1:
remote: [build] > /usr/local/zig/zig build-exe -lreadline -ODebug -Mroot=/app/src/main.zig -lc --cache-dir /app/.zig-cache --global-cache-dir /root/.cache/zig --name main --zig-lib-dir /usr/local/zig/lib/ --listen=- 
remote: [build] > Build Summary: 0/3 steps succeeded; 1 failed
remote: [build] > install transitive failure
remote: [build] > +- install main transitive failure
remote: [build] > +- zig build-exe main Debug native failure
remote: [build] > error: the following build command failed with exit code 1:
remote: [build] > /app/.zig-cache/o/5a1025b01098546404c87e4cf16c3fdd/build /usr/local/zig/zig /usr/local/zig/lib /app /app/.zig-cache /root/.cache/zig --seed 0xfadc1c90 -Z43d49f747b4eb4ce
remote: [build] Error: process "/bin/sh -c .codecrafters/compile.sh" did not complete successfully: exit code: 1.
remote: [build] > /usr/lib/libreadline.a
remote: [build] > 
remote: [build] > error: the following command exited with error code 1:
remote: [build] > /usr/local/zig/zig build-exe -lreadline -ODebug -Mroot=/app/src/main.zig -lc --cache-dir /app/.zig-cache --global-cache-dir /root/.cache/zig --name main --zig-lib-dir /usr/local/zig/lib/ --listen=- 
remote: [build] > Build Summary: 0/3 steps succeeded; 1 failed
remote: [build] > install transitive failure
remote: [build] > +- install main transitive failure
remote: [build] > +- zig build-exe main Debug native failure
remote: [build] > error: the following build command failed with exit code 1:
remote: [build] > /app/.zig-cache/o/5a1025b01098546404c87e4cf16c3fdd/build /usr/local/zig/zig /usr/local/zig/lib /app /app/.zig-cache /root/.cache/zig --seed 0xfadc1c90 -Z43d49f747b4eb4ce
remote: [build] Build failed. Check the logs above for the reason.
remote: [build] If you think this is a CodeCrafters error, please contact us at hello@codecrafters.io.
remote: 
remote: 
remote: Looks like your codebase failed to build.
remote: If you think this is a CodeCrafters error, please let us know at hello@codecrafters.io.

```

Not sure how to deal with this, or how to figure out the right thing to do. Interestingly enough, it does look like the codecrafters machine has the library _headers_ installed, or it wouldn’t build properly, but where’s the actual library?

If it matters, this is my build.zig diff:

```diff
diff --git a/build.zig b/build.zig
index d211b57..dcc7cd1 100644
--- a/build.zig
+++ b/build.zig
@@ -8,6 +8,8 @@ pub fn build(b: *std.Build) void {
         .target = b.standardTargetOptions(.{}),
         .optimize = b.standardOptimizeOption(.{}),
     });
+ exe.linkLibC();
+ exe.linkSystemLibrary("readline");
 
     // This declares intent for the executable to be installed into the
     // standard location when the user invokes the "install" step (the default

```

---

<div class="post-metadata">

### Author: ![levitte](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/levitte/32/8971_2.png) [@levitte](https://forum.codecrafters.io/u/levitte)
#### Post date: [April 10, 2025, 7:20pm UTC](https://forum.codecrafters.io/t/qp2-zig-using-readline-huh/8554/4 "2025-04-10T19:20:11Z")

</div>

I was incorrect in assuming the readline headers are installed… but all the same, if I want to follow that recommendation (and I do), how do I go about it?

---

<div class="post-metadata">

### Author: ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)
#### Post date: [April 11, 2025, 2:41am UTC](https://forum.codecrafters.io/t/qp2-zig-using-readline-huh/8554/5 "2025-04-11T02:41:06Z")

</div>

Hey @levitte, we’ve now upgraded the Zig buildpack to support readline.

To get started, you’ll need to `@cInclude("stdio.h");`

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/4/4d85d8c0e857dcb08bc5dc8b49ed2e43540fe758.png)

Your code may still need a few tweaks to compile. Let me know if you run into any issues!

---

<div class="post-metadata">

### Author: ![levitte](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/levitte/32/8971_2.png) [@levitte](https://forum.codecrafters.io/u/levitte)
#### Post date: [April 11, 2025, 3:09am UTC](https://forum.codecrafters.io/t/qp2-zig-using-readline-huh/8554/7 "2025-04-11T03:09:35Z")

</div>

And now it builds, thank you!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)
#### Post date: [April 20, 2025, 9:02am UTC](https://forum.codecrafters.io/t/qp2-zig-using-readline-huh/8554/8 "2025-04-20T09:02:59Z")

</div>

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