Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while compiling PortAudio examples

Tags:

c

portaudio

(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

like image 826
Dax Amin Avatar asked Sep 26 '22 13:09

Dax Amin


1 Answers

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.

like image 91
undur_gongor Avatar answered Oct 13 '22 00:10

undur_gongor