简体   繁体   English

编译PortAudio示例时出错

[英]Error while compiling PortAudio examples

(I am on Ubuntu) I am trying to run the PortAudio examples, but getting many errors (mentioned below). (我在Ubuntu上)我正在尝试运行PortAudio示例,但是遇到了很多错误(如下所述)。 I have placed the header file portaudio.h in the directory of the program. 我已将头文件portaudio.h放在程序目录中。 I have no idea about it. 我不知道。 I think it is linker error. 我认为这是链接器错误。 Please help! 请帮忙!

/tmp/cc5EbTlT.o: In function main': paex_record.c:(.text+0x37e): undefined reference to Pa_Initialize' paex_record.c:(.text+0x397): undefined reference to Pa_GetDefaultInputDevice' paex_record.c:(.text+0x3de): undefined reference to Pa_GetDeviceInfo' paex_record.c:(.text+0x436): undefined reference to Pa_OpenStream' paex_record.c:(.text+0x45a): undefined reference to Pa_StartStream' paex_record.c:(.text+0x493): undefined reference to Pa_Sleep' paex_record.c:(.text+0x4c2): undefined reference to Pa_IsStreamActive' paex_record.c:(.text+0x4eb): undefined reference to Pa_CloseStream' paex_record.c:(.text+0x5fa): undefined reference to Pa_GetDefaultOutputDevice' paex_record.c:(.text+0x641): undefined reference to Pa_GetDeviceInfo' paex_record.c:(.text+0x6b2): undefined reference to Pa_OpenStream' paex_record.c:(.text+0x6e3): undefined reference to Pa_StartStream' paex_record.c:(.text+0x71c): undefined reference to Pa_Sleep' paex_record.c:(.text+0x728): undefined reference to Pa_IsStreamActive' paex_record.c:(.text+0x74e): undefined reference to /tmp/cc5EbTlT.o:在函数main': paex_record.c:(.text+0x37e): undefined reference to Pa_Initialize'paex_record.c :(。text + 0x397):未定义引用Pa_GetDefaultInputDevice' paex_record.c:(.text+0x3de): undefined reference to Pa_GetDeviceInfo'paex_record.c :(。text + 0x436):未定义引用Pa_OpenStream' paex_record.c:(.text+0x45a): undefined reference to Pa_StartStream'paex_record.c :(。text + 0x493):未定义引用Pa_Sleep' paex_record.c:(.text+0x4c2): undefined reference to Pa_IsStreamActive'paex_record.c :(。text + 0x4eb):未定义引用Pa_CloseStream' paex_record.c:(.text+0x5fa): undefined reference to Pa_GetDefaultOutputDevice'paex_record.c :(。text + 0x641):未定义引用Pa_GetDeviceInfo' paex_record.c:(.text+0x6b2): undefined reference to Pa_OpenStream'paex_record.c :(。text + 0x6e3):undefined引用Pa_StartStream' paex_record.c:(.text+0x71c): undefined reference to Pa_Sleep'paex_record.c :(。text + 0x728):对Pa_IsStreamActive' paex_record.c:(.text+0x74e): undefined reference to未定义引用 Pa_IsStreamActive' paex_record.c:(.text+0x74e): undefined reference to Pa_CloseStream' paex_record.c:(.text+0x77d): undefined reference to Pa_Terminate' paex_record.c:(.text+0x7e5): undefined reference to Pa_GetErrorText' collect2: error: ld returned 1 exit status Pa_IsStreamActive' paex_record.c:(.text+0x74e): undefined reference to Pa_CloseStream'paex_record.c :(。text + 0x77d):未定义引用Pa_Terminate' paex_record.c:(.text+0x7e5): undefined reference to Pa_GetErrorText' collect2:错误:ld返回1退出状态

Assuming you are compiling using gcc and you have a single C file foo.c , the compiler command would be 假设您正在使用gcc编译并且您有一个C文件foo.c ,编译器命令将是

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

The -l parameters are there to link the required libraries to your program, eg -lrt will link librt.a . -l参数用于将所需的库链接到您的程序,例如-lrt将链接librt.a The order does matter. 订单很重要。

I got the required libraries from here: http://www.portaudio.com/docs/v19-doxydocs/compile_linux.html#comp_linux3 . 我从这里获得了所需的库: http//www.portaudio.com/docs/v19-doxydocs/compile_linux.html#comp_linux3 Don't know if they are correct. 不知道他们是否正确。 At least you need -lportaudio , obviously. 至少你需要-lportaudio ,显然。

If the libraries are not found, you have to provide gcc a path, eg 如果找不到库,则必须提供gcc路径,例如

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

Regarding the header, you don't actually need to copy it into your program's directory. 关于标题,您实际上不需要将其复制到程序的目录中。 You'd rather include it as 你宁愿把它包括在内

#include <portaudio.h>

and add its directory to the include search path: 并将其目录添加到包含搜索路径:

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

Of course, all this is better done in a Makefile. 当然,所有这些都在Makefile中做得更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM