Linking for a very basic Csound c++ program on Mac is failing

Dear Community,

I have a very basic Csound C++ API program which I am trying to compile and link. I work on a Mac 12.6.3.

The program is:

#include <csound.hpp>

int main(int argc, const char** argv) {
  Csound csound; // csound object
  int error; // error code

  // compile CSD and start the engine
  error = csound.Compile(argc, argv);

  while (!error)
    error = csound.PerformKsmps();

  return 0;

The command line that I use to compile and link is the following:

g++ ./main.cpp -DUSE_DOUBLE -o ./main -I/Library/Frameworks/CsoundLib64.framework/Versions/6.0/Headers -L/Library/Frameworks/CsoundLib64.framework -L/Library/Frameworks/CsoundLib64.framework/libs -L/Library/Frameworks -lCsoundLib64 -L/usr/lib -lcurl -lz -lsndfile

but I get the error:

  "_vDSP_create_fftsetupD", referenced from:
      _csoundRealFFT2Setup in libCsoundLib64.a(fftlib.c.o)
  "_vDSP_destroy_fftsetupD", referenced from:
      _setupDispose in libCsoundLib64.a(fftlib.c.o)
  "_vDSP_fft_zripD", referenced from:
      _csoundRealFFT2 in libCsoundLib64.a(fftlib.c.o)
      _vDSP_DCT_execute in libCsoundLib64.a(fftlib.c.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I am guessing that I am missing a library I have to link to.

What am I doing wrong?

Thank you very much in advance.

Victor is the MacOS expert around here, I’ll reach out to him and see if he can help :+1:

1 Like

From Victor:

I think his problem might be that -lCsoundLib64 is linking to the static library libCsound.a. For that you
need to pass all the other libraries (which you should not when linking to the dynamic library in the framework).
The missing framework is Accelerate I think. However I would advise to always link to the framework instead,
which is a dynamic link and that sorts all the dependencies. This is the right way to do it, plus you don’t need to
guess what libraries you need. Also you don’t need to install any extra libraries like libsndfile

So with a standard installation of Csound, all you need is

c++ -o test main.cpp -I/Library/Frameworks/CsoundLib64.framework/Headers -F/Library/Frameworks -framework CsoundLib64

That is, you are linking to the framework. Furthermore if you add the framework name to the header #include,

#include <CsoundLib64/csound.hpp>

you can even remove -I path,

c++ -o test maincs.cpp -F/Library/Frameworks -framework CsoundLib64

which is very handy I think.

Prof. Victor Lazzarini
Maynooth University

1 Like

That worked!

Thank you very much!!!

We’ll thank Victor :slight_smile:

1 Like