Thank you, though it would be great if there was a paired down hello world example (with an example of linking still), and redis is C I don't see any example of C++ compilation in github.com/kristoff-it/redis/blob/... ?
Edit, all good, I didn't realize addCSourceFiles is also for CPP files and then the only other step is linkLibCpp:
conststd=@import("std");pubfnbuild(b:*std.build.Builder)void{consttarget=b.standardTargetOptions(.{});constmode=b.standardReleaseOptions();constmy_app=b.addExecutable("my_app",null);my_app.setTarget(target);my_app.setBuildMode(mode);my_app.install();// Add your .addIncludeDir or .linkLibrary heremy_app.linkLibCpp();my_app.addCSourceFiles(&.{"src/main.cc",},&.{"-std=c++20",});}
Yes, jemalloc is the depedency that makes Redis technically also a C++ project, but you're right, we didn't build it once we started doing cross-compilation (and instead defaulted to vanilla malloc), but we did compile it in the beginning when just replacing clang with zig cc.
how do you go about calling cpp from zig? you need to write a C wrapper, correct? Is there a tutorial on how to write these kinds of wrappers?
you probably also need to handle exceptions and turn them into normal value like errors, right?
I came accross this one: teddy.ch/c++_library_in_c it is not specific to zig. I guess especially exceptions need to be handled carefully, because zig does not support that, right?
For further actions, you may consider blocking this person and/or reporting abuse
Thank you, though it would be great if there was a paired down hello world example (with an example of linking still), and redis is C I don't see any example of C++ compilation in github.com/kristoff-it/redis/blob/... ?
Edit, all good, I didn't realize
addCSourceFiles
is also for CPP files and then the only other step islinkLibCpp
:Yes, jemalloc is the depedency that makes Redis technically also a C++ project, but you're right, we didn't build it once we started doing cross-compilation (and instead defaulted to vanilla malloc), but we did compile it in the beginning when just replacing
clang
withzig cc
.is it possible to call cpp directly from zig or do I need to make a C wrapper for cpp code and then call that from zig?
you have to make a C wrapper
how do you go about calling cpp from zig? you need to write a C wrapper, correct? Is there a tutorial on how to write these kinds of wrappers?
you probably also need to handle exceptions and turn them into normal value like errors, right?
I came accross this one: teddy.ch/c++_library_in_c it is not specific to zig. I guess especially exceptions need to be handled carefully, because zig does not support that, right?