Hi,
I am new to zig, I was playing with zig build system to get a better understanding of how it works. I have single header CPP which gets compiled easily with “zig c++ test.cpp simdjson.cpp -o test”. now I changed the test.cpp to test.zig
const std = @import("std");
const json = @cImport({
@cInclude("simdjson.h");
});
pub fn main() !void{
const parser = json.ondemand.parser;
const file = json.padded_string.load("twitter.json");
const tw = parser.iterate(file);
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {s}!\n", .{tw});
}
and this is my build.zig
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const cflags = [_][]const u8{"-std=c++17", "-fno-sanitize=undefined"};
const lib = b.addStaticLibrary(.{
.name = "simdjson",
.target = target,
.optimize = optimize,
.link_libc = true,
});
lib.linkLibCpp();
lib.addCSourceFile(.{
.file = std.Build.FileSource.relative("simdjson.cpp"),
.flags = &cflags
});
lib.addIncludePath(.{ .path = "./header" });
lib.installHeader("./header/simdjson.h", "simdjson.h");
//b.installArtifact(lib);
const exe = b.addExecutable(.{
.name = "exe",
.root_source_file = .{ .path = "test.zig" },
.target = target,
.optimize = optimize,
});
exe.linkLibrary(lib);
exe.linkLibCpp();
exe.addCSourceFile(.{
.file = std.Build.FileSource.relative("simdjson.cpp"),
.flags = &cflags
});
//exe.addIncludePath(.{ .path = "./header" });
b.installArtifact(exe);
}
this gives me " error: C import failed". I would be appreciative if anyone can help me with this.