【问题标题】:Error while compiling PortAudio examples编译 PortAudio 示例时出错
【发布时间】:2016-01-03 12:54:27
【问题描述】:

(我在 Ubuntu 上)我正在尝试运行 PortAudio 示例,但遇到了很多错误(如下所述)。我已经把头文件portaudio.h放在了程序的目录下。我对此一无所知。我认为这是链接器错误。请帮忙!

/tmp/cc5EbTlT.o:在函数main': paex_record.c:(.text+0x37e): undefined reference toPa_Initialize' paex_record.c:(.text+0x397): 未定义引用Pa_GetDefaultInputDevice' paex_record.c:(.text+0x3de): undefined reference toPa_GetDeviceInfo' paex_record.c:(.text+0x436): 未定义引用Pa_OpenStream' paex_record.c:(.text+0x45a): undefined reference toPa_StartStream' paex_record.c:(.text+0x493): 未定义引用Pa_Sleep' paex_record.c:(.text+0x4c2): undefined reference toPa_IsStreamActive' paex_record.c:(.text+0x4eb): 未定义对Pa_CloseStream' paex_record.c:(.text+0x5fa): undefined reference toPa_GetDefaultOutputDevice' 的引用 paex_record.c:(.text+0x641): 未定义对Pa_GetDeviceInfo' paex_record.c:(.text+0x6b2): undefined reference toPa_OpenStream' 的引用 paex_record.c:(.text+0x6e3): 未定义引用Pa_StartStream' paex_record.c:(.text+0x71c): undefined reference toPa_Sleep' paex_record.c:(.text+0x728): 未定义引用Pa_IsStreamActive' paex_record.c:(.text+0x74e): undefined reference toPa_CloseStream' paex_record.c:(.text+0x77d): 未定义引用Pa_Terminate' paex_record.c:(.text+0x7e5): undefined reference toPa_GetErrorText' collect2:错误:ld 返回 1 个退出状态

【问题讨论】:

  • 是的,这是链接器错误。你是如何调用链接器的?
  • 我试图在答案中给出一些提示。如果这没有帮助,请告诉我们您是如何运行编译器/链接器的。我的意思是,来自 shell(哪个命令?)或来自 IDE(哪个?)或 ...?

标签: c portaudio


【解决方案1】:

假设您使用 gcc 进行编译并且您有一个 C 文件 foo.c,编译器命令将是

gcc -o foo foo.c -lrt -lasound -ljack -lpthread -lportaudio

-l 参数用于将所需的库链接到您的程序,例如-lrt 将链接librt.a。顺序很重要。

我从这里获得了所需的库:http://www.portaudio.com/docs/v19-doxydocs/compile_linux.html#comp_linux3。不知道他们是否正确。显然,至少你需要-lportaudio

如果找不到库,则必须为 gcc 提供路径,例如

gcc -L/usr/lib -o foo foo.c -lrt -lasound -ljack -lpthread -lportaudio

关于标题,您实际上不需要将其复制到程序目录中。您宁愿将其包含为

#include <portaudio.h>

并将其目录添加到包含搜索路径:

gcc -I/usr/include -L/usr/lib -o foo foo.c -lrt -lasound -ljack -lpthread -lportaudio

当然,所有这些都最好在 Makefile 中完成。

【讨论】:

  • 它之前工作得非常好,但是在重新安装 portaudio 后,每当我运行任何程序时都会出现这个错误 - /usr/bin/ld: 找不到 -lportaudio collect2: error: ld returned 1 exit status Please帮助。
  • 您必须找到libportaudio.alibportaudio.so 的位置,并用-L/path/to/lib/file/directory 告诉链接器路径。它应该类似于/usr/lib/i386-linux-gnu
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-25
  • 1970-01-01
  • 1970-01-01
  • 2020-03-19
相关资源
最近更新 更多