我正在尝试使用PortAudio通过麦克风进行音频录制。但是我遇到了很多错误-
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
我知道这是一个链接器错误,但无法从我下载的portaudio中找到任何.lib文件。我该如何解决这个问题?
答案 0 :(得分:0)
嘿>
您似乎在尝试构建其中一个端口音频示例,而无需先构建和/或链接portaudio库!
自从您使用Windows以来,主要有两种构建portaudio的方法(官方文档参考):
使用Visual Studio (VS):portaudio下载提供了一个VS项目,您必须对其进行一些小更改,然后才能(希望)进行编译。
With MinGW:在Windows上构建portaudio的命令行版本。如果尚未安装,则需要安装MinGW,但我认为这种方法比我过去使用Visual Studio尝试的要容易得多。
您使用的任何一种技术都会生成一个静态.lib文件,然后您可以将其用于链接到您的项目(即,您尝试编译的源文件)。
因此,由于您是Windows用户,所以如果您想准备安装项目,建议您在Visual Studio中执行此操作(创建一个空的c ++命令行程序,并添加paex_record.c文件)。下面是在VS中设置静态库的快速方法。
引用Project中的库头(portaudio.h) 属性-> C / C ++->常规->其他包含目录
在Project Properties-> Linker-> Input
有关更多信息 creating and using static libs。
在我看来,使用MinGW实际上要简单得多,但是如果您不习惯在命令行中工作,则可能不喜欢它。
假设您的项目目录包含三个文件(为简单起见):
Project Folder
|paex_record.c
|portaudio.lib
|portaudio.h
然后,编译命令(source)为:
cd /Project/Directory
gcc paex_record.c -lportaudio