c++macoscompilationrtaudio

RT audio Mac error g++ compiling error


Having problems getting rt audio to compile using simple application

#include "RtAudio.h"

int main()
{
        RtAudio *audio = 0;
        audio = new RtAudio;
        delete audio;
return 0;
}

to compile

g++ -Wall -D__MACOSX_CORE__ -o probe rtaudio.cpp RtAudio.cpp -framework CoreAudio -lpthread 

error

Undefined symbols for architecture x86_64:
  "RtAudio::RtAudio(RtAudio::Api)", referenced from:
      _main in rtaudio-e456a2.o
      _main in RtAudio-a64f56.o
"RtAudio::~RtAudio()", referenced from:
  _main in rtaudio-e456a2.o
  _main in RtAudio-a64f56.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution

  • You need to link your code with RtAudio library, so add -lrtAudio to your compile command:

    g++ -Wall -D__MACOSX_CORE__ -o probe RtAudio.cpp -framework CoreAudio -lpthread -lrtAudio
    

    And you have included two RtAudio, one "rtaudio.cpp" and two RtAudio.cpp, you should clear rtaudio.cpp, because you included #include "RtAudio.h" with uppercase in your main