You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- `exe.addIncludePath()` takes a `LazyPath`, and it just so happens that `std.Build` (the type of `b`) contains a function to provide a `LazyPath` object given a string.
126
126
- `exe.addCSourceFiles()` takes a `struct` that includes a `files` property. This property is a pointer to an array of strings. I'll break down `&[_][]const u8 {}` real quick in plain English:
127
127
128
-
```zig
128
+
```c
129
129
&[_][]const u8 {
130
130
"..",
131
131
"...",
@@ -143,6 +143,7 @@ Things to note:
143
143
// a reference to an automatically sized array of array of constants u8 objects.
144
144
// a pointer to the address in memory where an array of arrays of u8 exists
145
145
```
146
+
146
147
_Probably overkill of an explanation, but maybe someone will benefit from this._
147
148
148
149
- Next is `exe.linkLibC()`. This is the extremely convenient way that Zig links to libc. There's also `linkLibCpp()`, which could be useful to keep in mind. If you use a standard library, such as `stdio.h`, make sure to include `linkLibC()`, otherwise you'll get a compilation error when trying to build.
@@ -154,6 +155,7 @@ zig build
154
155
```
155
156
156
157
And run the resulting executable:
158
+
157
159
```sh
158
160
./zig-out/bin/c_compiled_with_zig_build.exe
159
161
10 + 5 = 15
@@ -166,8 +168,8 @@ Same results as compiling with `zig cc`! Very cool. Let's move on to using a bit
166
168
167
169
Basically, I want to recreate my `main.c` in Zig. In this case, this is trivial.
168
170
169
-
[`main.zig`](src/zig_linked_to_c.zig)
170
-
```zig
171
+
`main.zig`
172
+
```c
171
173
const std = @import("std");
172
174
const zmath = @cImport(@cInclude("zmath.h"));
173
175
@@ -189,8 +191,8 @@ Fairly simple to understand. The only gotcha is using printing the output. Next
189
191
we have to modify `build.zig` and point it to our `main.zig` file
190
192
instead of `main.c`.
191
193
192
-
[`build.zig`](build_zig_linked_to_c.zig)
193
-
```zig
194
+
`build.zig`
195
+
```c
194
196
const std = @import("std");
195
197
196
198
pub fn build(b: *std.Build) void {
@@ -231,7 +233,7 @@ exposing them to the application code.
0 commit comments