0

I'm trying to use PortAudio for audio recording through a microphone. But I get a bunch of errors -

Compiling single file...
--------
- Filename: C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples\paex_record.c
- Compiler Name: TDM-GCC 4.9.2 64-bit Debug

Processing C source file...
--------
- C Compiler: C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\gcc.exe
- Command: gcc.exe "C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples\paex_record.c" -o "C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples\paex_record.exe" -g3 -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include" -I"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\lib" -L"C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\lib" -L"C:\Users\Gumm\Downloads\pa_stable_v190600_20161030\portaudio\examples" -g3
C:\Users\Gumm\AppData\Local\Temp\ccih6neG.o: In function `main':
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:224: undefined reference to `Pa_Initialize'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:227: undefined reference to `Pa_GetDefaultInputDevice'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:234: undefined reference to `Pa_GetDeviceInfo'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:238: undefined reference to `Pa_OpenStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:249: undefined reference to `Pa_StartStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:255: undefined reference to `Pa_Sleep'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:253: undefined reference to `Pa_IsStreamActive'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:260: undefined reference to `Pa_CloseStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:303: undefined reference to `Pa_GetDefaultOutputDevice'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:310: undefined reference to `Pa_GetDeviceInfo'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:314: undefined reference to `Pa_OpenStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:327: undefined reference to `Pa_StartStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:332: undefined reference to `Pa_Sleep'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:332: undefined reference to `Pa_IsStreamActive'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:335: undefined reference to `Pa_CloseStream'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:342: undefined reference to `Pa_Terminate'
C:/Users/Gumm/Downloads/pa_stable_v190600_20161030/portaudio/examples/paex_record.c:349: undefined reference to `Pa_GetErrorText'
collect2.exe: error: ld returned 1 exit status


Compilation results...
--------
- Errors: 1
- Warnings: 0
- Compilation Time: 0.53s

I know this is a linker error but I am unable to find any .lib file from my download of portaudio. How do I resolve this issue?

blazingcannon
  • 37
  • 2
  • 9
  • yes. When, I press on build, I get these errors – blazingcannon Jul 16 '18 at 13:33
  • you mean create my own project, copy this example code and then build it? I have tried that too with the same result. If that's not what you mean, can you please elaborate? – blazingcannon Jul 16 '18 at 13:42
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mike Kinghan Jul 16 '18 at 14:15
  • @AlexF -portaudio download does contain a build directory but it does not contain any C/C++ file or header file. So,even if I try to build, it gives an error – blazingcannon Jul 16 '18 at 14:32
  • First, you should build Portaudio libraries using `cmake`. Then you can link them with your own project. – ConsistentProgrammer Jul 17 '18 at 12:57

1 Answers1

0

< /Hey >

It looks like you are trying to build one of the port audio examples, without first building and/or linking the portaudio library!

Building portaudio for windows

Since your on Windows, there's two main ways to build portaudio (official docs reference):

  1. With Visual Studio (VS) : The portaudio download provides a VS project that you have to change a few minor things before it should (hopefully) compile.

  2. With MinGW : A command line version of building portaudio on windows. You will need to install MinGW if you haven't already, but I think this method is much easier than my attempts with Visual Studio in the past.

Either technique you use will generate a static .lib file, which you can then be used to link to your project (i.e. the source file you are trying to compile).

Linking portaudio

Visual Studio

So since your on Windows, I would recommend doing this in Visual Studio (create a empty c++ command line program, and add the paex_record.c file ) if you want to have a setup project ready to go. Below is a quick way to setup a static lib in VS.

  • Reference the library header (portaudio.h) in Project Properties->C/C++->General->Additional Include Directories

  • Reference the .lib (portaudio.lib) in Project Properties->Linker->Input

More info on creating and using static libs.

MinGW

It's actually much simpler with MinGW in my opinion but if you aren't used to working in the command line you might not prefer it.

Assuming you have your project directory with three files (for simplicity):

Project Folder
     |paex_record.c
     |portaudio.lib
     |portaudio.h

Then the compile command (source) is:

 cd /Project/Directory
 gcc paex_record.c -lportaudio
WoodyDev
  • 1,386
  • 1
  • 9
  • 19