Hey there.
I’m trying to compile a very simple zig program that uses the C API.
const std = @import("std");
const cs = @cImport({
@cInclude("csound/csound.h");
});
pub fn main() !void {
const score =
\\ <CsoundSynthesizer>
\\ <CsOptions> -odac </CsOptions>
\\ <CsInstruments>
\\ instr 1
\\ out(linen(oscili(p4,p5),0.1,p3,0.1))
\\ endin
\\ </CsInstruments>
\\ <CsScore>
\\ i1 0 5 1000 440
\\ </CsScore>
\\ </CsoundSynthesizer>
;
const csound = cs.csoundCreate(null);
defer {
_ = cs.csoundCleanup(csound);
cs.csoundReset(csound);
cs.csoundDestroy(csound);
}
if (cs.csoundCompileCsdText(csound, score) == 0) {
_ = cs.csoundStart(csound);
while (cs.csoundPerformKsmps(csound) == 0) {}
}
}
Roughly equivalent to the C example here: Csound API: Main Page
I’m linking in against libcsnd6 but it doesn’t find any symbol and when I’m listing libcsnd6.dylib content I don’t see them even though the csound.h
header does define them
λ giann [~/git/synth] → zig run -I/opt/homebrew/Cellar/csound/6.18.1_9/include -L/opt/homebrew/Cellar/csound/6.18.1_9/lib -lcsnd6 src/main.zig
error: undefined symbol: _csoundCleanup
note: referenced by /Users/giann/.cache/zig/o/2f4f63526e79e71f102d7a5ee85e46c6/main.o:_main.main
error: undefined symbol: _csoundCompileCsdText
note: referenced by /Users/giann/.cache/zig/o/2f4f63526e79e71f102d7a5ee85e46c6/main.o:_main.main
error: undefined symbol: _csoundCreate
note: referenced by /Users/giann/.cache/zig/o/2f4f63526e79e71f102d7a5ee85e46c6/main.o:_main.main
error: undefined symbol: _csoundDestroy
note: referenced by /Users/giann/.cache/zig/o/2f4f63526e79e71f102d7a5ee85e46c6/main.o:_main.main
error: undefined symbol: _csoundPerformKsmps
note: referenced by /Users/giann/.cache/zig/o/2f4f63526e79e71f102d7a5ee85e46c6/main.o:_main.main
error: undefined symbol: _csoundReset
note: referenced by /Users/giann/.cache/zig/o/2f4f63526e79e71f102d7a5ee85e46c6/main.o:_main.main
error: undefined symbol: _csoundStart
note: referenced by /Users/giann/.cache/zig/o/2f4f63526e79e71f102d7a5ee85e46c6/main.o:_main.main
λ giann [~/git/synth] → nm -gU /opt/homebrew/Cellar/csound/6.18.1_9/lib/libcsnd6.6.0.dylib | grep _csoundCreate
# nothing...
Am I linking against the wrong library?
I have installed csound with brew install csound