Error while compiling PortAudio examples

自古美人都是妖i 提交于 2019-12-22 08:59:21

问题


(I am on Ubuntu) I am trying to run the PortAudio examples, but getting many errors (mentioned below). I have placed the header file portaudio.h in the directory of the program. 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 toPa_Initialize' paex_record.c:(.text+0x397): undefined reference to Pa_GetDefaultInputDevice' paex_record.c:(.text+0x3de): undefined reference toPa_GetDeviceInfo' paex_record.c:(.text+0x436): undefined reference to Pa_OpenStream' paex_record.c:(.text+0x45a): undefined reference toPa_StartStream' paex_record.c:(.text+0x493): undefined reference to Pa_Sleep' paex_record.c:(.text+0x4c2): undefined reference toPa_IsStreamActive' paex_record.c:(.text+0x4eb): undefined reference to Pa_CloseStream' paex_record.c:(.text+0x5fa): undefined reference toPa_GetDefaultOutputDevice' paex_record.c:(.text+0x641): undefined reference to Pa_GetDeviceInfo' paex_record.c:(.text+0x6b2): undefined reference toPa_OpenStream' paex_record.c:(.text+0x6e3): undefined reference to Pa_StartStream' paex_record.c:(.text+0x71c): undefined reference toPa_Sleep' paex_record.c:(.text+0x728): undefined reference to Pa_IsStreamActive' paex_record.c:(.text+0x74e): undefined reference toPa_CloseStream' paex_record.c:(.text+0x77d): undefined reference to Pa_Terminate' paex_record.c:(.text+0x7e5): undefined reference toPa_GetErrorText' collect2: error: ld returned 1 exit status


回答1:


Assuming you are compiling using gcc and you have a single C file foo.c, the compiler command would be

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

The -l parameters are there to link the required libraries to your program, e.g. -lrt will link 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. Don't know if they are correct. At least you need -lportaudio, obviously.

If the libraries are not found, you have to provide gcc a path, e.g.

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.



来源:https://stackoverflow.com/questions/32972796/error-while-compiling-portaudio-examples

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!