hi there, i’m trying to use the RtMidi library in this zig project: GitHub - patchsoul/patchsoul: mono repo for game tools, but i’m getting an interesting error when i step through the program at rtmidi_in_create_default
, which should succeed without any problems because it’s just creating a new pointer to a default RtMidiIn (no errors should throw there):
gdb zig-out/bin/patchsoul
...
(gdb) b rtmidi_in_create_default
Breakpoint 1 at 0x11836c8: file /home/lowagner/.cache/zig/p/122098d759a37725c9913a08f54112671f9f00a458a5c8102e2f5cdd9f9dac98ca07/rtmidi_c.cpp, line 171.
(gdb) run
Starting program: /home/lowagner/code/patchsoul/zig-out/bin/patchsoul
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, rtmidi_in_create_default () at /home/lowagner/.cache/zig/p/122098d759a37725c9913a08f54112671f9f00a458a5c8102e2f5cdd9f9dac98ca07/rtmidi_c.cpp:171
171 RtMidiWrapper* wrp = new RtMidiWrapper;
(gdb) s
operator new (size=32) at /home/lowagner/zig/0.13.0/files/lib/libcxxabi/src/stdlib_new_delete.cpp:67
67 void* p = operator_new_impl(size);
(gdb) s
operator_new_impl (size=32) at /home/lowagner/zig/0.13.0/files/lib/libcxxabi/src/stdlib_new_delete.cpp:51
51 if (size == 0)
(gdb) s
54 while ((p = std::malloc(size)) == nullptr) {
(gdb) s
__GI___libc_malloc (bytes=32) at ./malloc/malloc.c:3287
3287 ./malloc/malloc.c: No such file or directory.
so i imagine i have the build.zig setup wrong, and admittedly it is hacked together based on internet sources and duct tape. but i am linking libC and libCpp in my build.zig file:
const rtmidi_dep_c = b.dependency("rtmidi", .{
.target = target,
.optimize = optimize,
});
const rtmidi_zig = b.addStaticLibrary(.{
.name = "rtmidi-zig",
.root_source_file = b.path("rtmidi/rtmidi.zig"),
.target = target,
.optimize = optimize,
});
rtmidi_zig.linkLibC();
rtmidi_zig.linkLibCpp();
rtmidi_zig.addCSourceFiles(.{
.root = rtmidi_dep_c.path(""),
.files = &.{ "rtmidi_c.cpp", "RtMidi.cpp" },
});
rtmidi_zig.installHeadersDirectory(rtmidi_dep_c.path(""), "", .{
.include_extensions = &.{ "rtmidi_c.h", "RtMidi.h" },
});
b.installArtifact(rtmidi_zig);
const rtmidi = b.addModule("rtmidi", .{
.root_source_file = b.path("rtmidi/rtmidi.zig"),
});
rtmidi.addIncludePath(rtmidi_dep_c.path(""));
rtmidi.linkLibrary(rtmidi_zig);
rtmidi.addImport("lib", lib);
how do i make sure that malloc is available to this rtmidi
module? i don’t care too much about the internal structure of this C library wrapper, only that it is available via @import("rtmidi")
, so if it can be simplified that’s even better.
i’m on zig 0.13.0 if it matters. thanks in advance for any help!