I’m trying to build CBQN using Zig. It uses a makefile. Basically I’m using make but trying to replace all calls to gcc with zig cc. So I’ve tried aliasing alias gcc="zig cc" and I’ve also tried adding this line to the makefile: CC = zig cc. Both give me an Error: Failed to spawn zig cc error. I’m pretty new to Zig (I’m more of a seasoned python dev, so I don’t know makefiles too much either). I wanted to incrementally add a bit of Zig to this project as a nice way to get into Zig, but first I need it to compile. I’m using a nix flake for my zig environment btw. Any advice on where to start on this? Essentially my question is, what do people do for building makefile-based C projects using zig?
try make CC="zig cc" CXX="zig c++"
Sorry to have to cover the basics, but the problem you describe sounds like zig isn’t on the path that make is using. Are you sure your flake is active when make is running? I can see that make isn’t specified in your flake, so presumably that is installed as a system package? Can it see zig?
What you’re doing otherwise is correct, so I think this is a nix problem more that a zig one.
Yeah I thought Nix might be the problem, so on a MacOS machine I installed zig using brew, and I still get exactly the same error. Maybe CBQN is a bit too complicated and I should try something simpler first.
If you can’t find zig on the path then it’s not about the complexity of the project.
Presumably you can do a zig init and zig build just to build the hello world example?
Hmmmm… Not sure I know how to help then.
I have filed an issue with CBQN to see if they might be doing anything funky in their makefile. The error is when it tries to “spawn” zig cc so that might be tripping things up.
Error: Failed to spawn zig cc
make[1]: *** [to-bqn-build] Error 1
make: *** [o3] Error 2
³tbrowne@Mac ~/scratch/CBQN ❯
I am understanding that make spawns zig cc instead of zig and pass the argument cc.
You can work around by making two helper scripts:
#!/bin/sh
exec zig cc "$@"
Name them zig-cc and zig-c++, make them executable (chmod +x zig-cc zig-c++) and run make CC=zig-cc CXX=zig-c++.
Works a charm but I needed to to export PATH=“$PWD:$PATH” so to eliminate ./ prepend.
