RT audio Mac 错误 g++ 编译错误

RT audio Mac error g++ compiling error

使用简单的应用程序编译 rt 音频时遇到问题

#include "RtAudio.h"

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

编译

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

错误

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)

您需要 link 您的代码使用 RtAudio 库,因此将 -lrtAudio 添加到您的编译命令中:

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

并且您已经包含了两个 RtAudio,一个 "rtaudio.cpp" 和两个 RtAudio.cpp,您应该清除 rtaudio.cpp,因为您在 main[=] 中包含了大写的 #include "RtAudio.h" 13=]