尝试 portaudio 示例,但得到 "ld: symbol(s) not found for architecture x86_64"

trying portaudio example, but getting "ld: symbol(s) not found for architecture x86_64"

我正在尝试在 Mac OS 10.10 上使用 portaudio,但在尝试编译示例程序时出现错误。这是我所做的:

-./configure && make.没问题。

-将示例文件 "pa_devs.c"、libportaudio.a 和 portaudio.h 复制到名为 Test1

的单独目录中

-尝试编译它

gcc -o Test1 pa_devs.c libportaudio.a -lm

-出现此错误:

Undefined symbols for architecture x86_64:
  "_AudioConvertHostTimeToNanos", referenced from:
      _GetStreamTime in libportaudio.a(pa_mac_core.o)
      _AudioIOProc in libportaudio.a(pa_mac_core.o)
  "_AudioConverterDispose", referenced from:
      _CloseStream in libportaudio.a(pa_mac_core.o)
  "_AudioConverterFillBuffer", referenced from:
      _AudioIOProc in libportaudio.a(pa_mac_core.o)
  "_AudioConverterNew", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "_AudioConverterReset", referenced from:
      _StartStream in libportaudio.a(pa_mac_core.o)
  "_AudioConverterSetProperty", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "_AudioDeviceAddPropertyListener", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
      _SetupDevicePropertyListeners in libportaudio.a(pa_mac_core.o)
      _AudioDeviceSetPropertyNowAndWaitForChange in libportaudio.a(pa_mac_core_utilities.o)
  "_AudioDeviceGetProperty", referenced from:
      _PaMacCore_GetChannelName in libportaudio.a(pa_mac_core.o)
      _PaMacCore_GetBufferSizeRange in libportaudio.a(pa_mac_core.o)
      _PaMacCore_Initialize in libportaudio.a(pa_mac_core.o)
      _OpenStream in libportaudio.a(pa_mac_core.o)
      _AudioDevicePropertyActualSampleRateListenerProc in libportaudio.a(pa_mac_core.o)
      _AudioDevicePropertyGenericListenerProc in libportaudio.a(pa_mac_core.o)
      _CalculateFixedDeviceLatency in libportaudio.a(pa_mac_core.o)
      ...
  "_AudioDeviceGetPropertyInfo", referenced from:
      _PaMacCore_GetChannelName in libportaudio.a(pa_mac_core.o)
      _PaMacCore_Initialize in libportaudio.a(pa_mac_core.o)
      _GetChannelInfo in libportaudio.a(pa_mac_core.o)
      _setBestSampleRateForDevice in libportaudio.a(pa_mac_core_utilities.o)
  "_AudioDeviceRemovePropertyListener", referenced from:
      _CloseStream in libportaudio.a(pa_mac_core.o)
      _AudioDeviceSetPropertyNowAndWaitForChange in libportaudio.a(pa_mac_core_utilities.o)
  "_AudioDeviceSetProperty", referenced from:
      _AudioDeviceSetPropertyNowAndWaitForChange in libportaudio.a(pa_mac_core_utilities.o)
      _setBestFramesPerBuffer in libportaudio.a(pa_mac_core_utilities.o)
     (maybe you meant: _AudioDeviceSetPropertyNowAndWaitForChange)
  "_AudioGetCurrentHostTime", referenced from:
      _GetStreamTime in libportaudio.a(pa_mac_core.o)
      _AudioIOProc in libportaudio.a(pa_mac_core.o)
  "_AudioHardwareGetProperty", referenced from:
      _PaMacCore_Initialize in libportaudio.a(pa_mac_core.o)
  "_AudioHardwareGetPropertyInfo", referenced from:
      _PaMacCore_Initialize in libportaudio.a(pa_mac_core.o)
  "_AudioObjectSetPropertyData", referenced from:
      _PaMacCore_Initialize in libportaudio.a(pa_mac_core.o)
  "_AudioOutputUnitStart", referenced from:
      _StartStream in libportaudio.a(pa_mac_core.o)
  "_AudioOutputUnitStop", referenced from:
      _StopStream in libportaudio.a(pa_mac_core.o)
      _AudioIOProc in libportaudio.a(pa_mac_core.o)
  "_AudioStreamGetProperty", referenced from:
      _CalculateFixedDeviceLatency in libportaudio.a(pa_mac_core.o)
  "_AudioUnitAddPropertyListener", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "_AudioUnitGetProperty", referenced from:
      _StopStream in libportaudio.a(pa_mac_core.o)
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
      _startStopCallback in libportaudio.a(pa_mac_core.o)
  "_AudioUnitInitialize", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "_AudioUnitRender", referenced from:
      _AudioIOProc in libportaudio.a(pa_mac_core.o)
  "_AudioUnitReset", referenced from:
      _StopStream in libportaudio.a(pa_mac_core.o)
  "_AudioUnitSetProperty", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "_AudioUnitUninitialize", referenced from:
      _CloseStream in libportaudio.a(pa_mac_core.o)
  "_CFRelease", referenced from:
      _PaMacCore_GetChannelName in libportaudio.a(pa_mac_core.o)
  "_CFStringCreateWithFormat", referenced from:
      _PaMacCore_GetChannelName in libportaudio.a(pa_mac_core.o)
  "_CFStringGetCString", referenced from:
      _PaMacCore_GetChannelName in libportaudio.a(pa_mac_core.o)
  "_CFStringGetLength", referenced from:
      _PaMacCore_GetChannelName in libportaudio.a(pa_mac_core.o)
  "_CloseComponent", referenced from:
      _CloseStream in libportaudio.a(pa_mac_core.o)
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "_FindNextComponent", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "_Gestalt", referenced from:
      _PaMacCore_Initialize in libportaudio.a(pa_mac_core.o)
  "_OpenAComponent", referenced from:
      _OpenAndSetupOneAudioUnit in libportaudio.a(pa_mac_core.o)
  "___CFConstantStringClassReference", referenced from:
      CFString in libportaudio.a(pa_mac_core.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我觉得我没有正确链接事物。有什么建议吗?

您需要包含 Apple 框架:

  • CoreServices.framework
  • CoreFoundation.framework
  • AudioUnit.framework
  • AudioToolbox.framework
  • CoreAudio.framework

就像你已经做的那样libportaudio.a

谢谢凯文!为了给 NetBeans 用户争取时间,我在 Mac OS X 10.12 sierra,Netbeans 8.2 上安装了 portaudio (http://macappstore.org/portaudio/)

  • 项目必须#include "portaudio.h"
  • 右键单击项目 > 属性
  • 构建>链接器
  • 附加选项,添加:

-v /usr/local/lib/libportaudio.a -framework CoreServices -framework CoreFoundation -framework AudioUnit -framework AudioToolbox -framework CoreAudio

现在可以了。这篇写的很详细,适合我这样的新手。