#Converting C to Zig for Beginners
1 messages · Page 1 of 1 (latest)
zig translate-c
translate-c is only designed for headers
Well it works for normal stuff but I get your point
Could you elaborate @fallow grail? I'd love to know where I could use zig translate-c in this post.
I havnt read the blog, prob should but you can use the addTranslateC function in build that will idk translate c code
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "main",
.root_module = b.addTranslateC(.{
.root_source_file = b.path("main.c"),
.target = target,
.optimize = optimize,
.link_libc = true,
}).createModule(),
});
b.installArtifact(exe);
const run = b.addRunArtifact(exe);
const run_step = b.step("run", "Runs the app");
run_step.dependOn(&run.step);
}
This works
Tho I see why you did things like you did since its how it was before and since addTranslateC wasnt used much before
also yes this works with multiple C files, just give it the entry and it works
also don't use @cImport since its depricated
also the print example is good for the writer but I think a more valid translation is just
std.debug.print rather than using the writer
also I've never used b.graph.host I dont recommend using it eighter since you don't get power over the target via the command line
also compiling every c source file into its own object is quite a bad way of doing it
Well I wont roast your blog anymore, its not always easy knowing what to do especialy since zig's build system is changing a lot currently
idk I hope this helped you in some way and feel free to ask about anything more
@ocean plover
Also I'd recommend you share your blog here also https://ziggit.dev/
No not at all, this is great. Thanks!
I'm looking for feedback since it makes the resource more useful and I get to learn too, I'll definitely change the writer and add the standard target stuff to the build.zig
Thanks so much!