我决定将我的音频项目移植到C并成功使用SDL库。我想使用由PortAudio提供的ASIO,因此我使用ASIO支持构建了PortAudio而没有错误。当我包含portaudio.h时,将库-lportaudio添加到链接器,构建所有内容并运行,没有问题。但是当我尝试调用任何portaudio函数(例如Pa_Initialize
)时,我得到了这个输出:
08:27:54 **** Incremental Build of configuration Debug for project PortAudioTest ****
Info: Internal Builder is used for build
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "..\\main.c"
gcc -o PortAudioTest.exe main.o -lportaudio
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_util.o): In function `PaUtil_GetTime':
D:\Dokumenty\Downloads\portaudio/src/os/win/pa_win_util.c:148: undefined reference to `timeGetTime@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `AdvanceToNextOutputBuffer':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2733: undefined reference to `waveOutWrite@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2739: undefined reference to `waveOutGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `AdvanceToNextInputBuffer':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2706: undefined reference to `waveInAddBuffer@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2712: undefined reference to `waveInGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `StopStream':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3538: undefined reference to `waveOutReset@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3542: undefined reference to `waveOutGetErrorTextA@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3551: undefined reference to `waveInReset@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3555: undefined reference to `waveInGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `ProcessingThreadProc':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2968: undefined reference to `waveOutGetPosition@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `TerminateWaveHeaders':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2099: undefined reference to `waveInUnprepareHeader@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2101: undefined reference to `waveOutUnprepareHeader@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `QueryOutputWaveFormatEx':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:543: undefined reference to `waveOutOpen@24'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:559: undefined reference to `waveOutGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `QueryInputWaveFormatEx':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:517: undefined reference to `waveInOpen@24'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:533: undefined reference to `waveInGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `InitializeWaveHeaders':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2049: undefined reference to `waveInPrepareHeader@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2059: undefined reference to `waveOutPrepareHeader@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:2063: undefined reference to `waveInGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `AbortStream':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3597: undefined reference to `waveOutReset@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3600: undefined reference to `waveOutGetErrorTextA@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3610: undefined reference to `waveInReset@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3613: undefined reference to `waveInGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `StartStream':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3235: undefined reference to `waveInAddBuffer@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3239: undefined reference to `waveInGetErrorTextA@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3252: undefined reference to `waveOutPause@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3327: undefined reference to `waveOutGetErrorTextA@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3323: undefined reference to `waveOutWrite@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3388: undefined reference to `waveInStart@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3393: undefined reference to `waveInGetErrorTextA@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3403: undefined reference to `waveOutRestart@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:3406: undefined reference to `waveOutGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `TerminateWaveHandles':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1940: undefined reference to `waveInClose@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1958: undefined reference to `waveInGetErrorTextA@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1947: undefined reference to `waveOutClose@4'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1962: undefined reference to `waveOutGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `InitializeWaveHandles':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1860: undefined reference to `waveInOpen@24'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1910: undefined reference to `waveOutGetErrorTextA@12'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1866: undefined reference to `waveOutOpen@24'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:1906: undefined reference to `waveInGetErrorTextA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `PaWinMme_Initialize':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:976: undefined reference to `waveInMessage@16'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:980: undefined reference to `waveOutMessage@16'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:984: undefined reference to `waveInGetNumDevs@0'
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:988: undefined reference to `waveOutGetNumDevs@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `InitializeInputDeviceInfo':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:692: undefined reference to `waveInGetDevCapsA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `InitializeOutputDeviceInfo':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:820: undefined reference to `waveOutGetDevCapsA@12'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_wmme.o): In function `PaWinMme_Initialize':
D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c:988: undefined reference to `waveOutGetNumDevs@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o): In function `Terminate':
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1409: undefined reference to `operator delete(void*)'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o): In function `GetStreamTime':
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:3538: undefined reference to `timeGetTime@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o): In function `PaAsio_Initialize':
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1382: undefined reference to `operator delete(void*)'
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1216: undefined reference to `operator new(unsigned int)'
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1216: undefined reference to `operator delete(void*)'
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1218: undefined reference to `__cxa_get_exception_ptr'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o): In function `bad_alloc':
c:/mingw/lib/gcc/mingw32/4.8.1/include/c++/new:54: undefined reference to `vtable for std::bad_alloc'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o): In function `PaAsio_Initialize':
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1218: undefined reference to `__cxa_begin_catch'
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1218: undefined reference to `std::bad_alloc::~bad_alloc()'
D:\Dokumenty\Downloads\portaudio/src/hostapi/asio/pa_asio.cpp:1218: undefined reference to `__cxa_end_catch'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o):pa_asio.cpp:(.rdata$_ZTISt9exception[__ZTISt9exception]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o):pa_asio.cpp:(.rdata$_ZTISt9bad_alloc[__ZTISt9bad_alloc]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_asio.o):pa_asio.cpp:(.eh_frame+0x6f7): undefined reference to `__gxx_personality_v0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_coinitialize.o): In function `PaWinUtil_CoInitialize':
D:\Dokumenty\Downloads\portaudio/src/os/win/pa_win_coinitialize.c:79: undefined reference to `CoInitialize@4'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(pa_win_coinitialize.o): In function `PaWinUtil_CoUninitialize':
D:\Dokumenty\Downloads\portaudio/src/os/win/pa_win_coinitialize.c:139: undefined reference to `CoUninitialize@0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTI8IUnknown[__ZTI8IUnknown]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTI5IASIO[__ZTI5IASIO]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTI21IASIOThiscallResolver[__ZTI21IASIOThiscallResolver]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTV8IUnknown[__ZTV8IUnknown]+0x8): undefined reference to `__cxa_pure_virtual'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTV8IUnknown[__ZTV8IUnknown]+0xc): undefined reference to `__cxa_pure_virtual'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTV8IUnknown[__ZTV8IUnknown]+0x10): undefined reference to `__cxa_pure_virtual'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTV5IASIO[__ZTV5IASIO]+0x8): undefined reference to `__cxa_pure_virtual'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTV5IASIO[__ZTV5IASIO]+0xc): undefined reference to `__cxa_pure_virtual'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(iasiothiscallresolver.o):iasiothiscallresolver.cpp:(.rdata$_ZTV5IASIO[__ZTV5IASIO]+0x10): more undefined references to `__cxa_pure_virtual' follow
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(asiodrivers.o): In function `Z14loadAsioDriverPc':
C:/MinGW/msys/1.0/asio/ASIOSDK/host/asiodrivers.cpp:11: undefined reference to `operator new(unsigned int)'
C:/MinGW/msys/1.0/asio/ASIOSDK/host/asiodrivers.cpp:11: undefined reference to `operator delete(void*)'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(asiodrivers.o):asiodrivers.cpp:(.eh_frame+0xff): undefined reference to `__gxx_personality_v0'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(asiolist.o): In function `deleteDrvStruct':
C:/MinGW/msys/1.0/asio/ASIOSDK/host/pc/asiolist.cpp:111: undefined reference to `operator delete(void*)'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(asiolist.o): In function `newDrvStruct':
C:/MinGW/msys/1.0/asio/ASIOSDK/host/pc/asiolist.cpp:75: undefined reference to `operator new[](unsigned int)'
C:/MinGW/msys/1.0/asio/ASIOSDK/host/pc/asiolist.cpp:80: undefined reference to `CLSIDFromString@8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(asiolist.o): In function `ZN14AsioDriverListC2Ev':
C:/MinGW/msys/1.0/asio/ASIOSDK/host/pc/asiolist.cpp:157: undefined reference to `CoInitialize@4'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(asiolist.o): In function `ZN14AsioDriverList14asioOpenDriverEiPPv':
C:/MinGW/msys/1.0/asio/ASIOSDK/host/pc/asiolist.cpp:184: undefined reference to `CoCreateInstance@20'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libportaudio.a(asiolist.o): In function `ZN14AsioDriverListD2Ev':
C:/MinGW/msys/1.0/asio/ASIOSDK/host/pc/asiolist.cpp:164: undefined reference to `CoUninitialize@0'
collect2.exe: error: ld returned 1 exit status
08:27:55 Build Finished (took 858ms)
我在Windows 10 64bit上使用32位MinGW和Eclipse。
我也不太明白,为什么要使用来自D:\Dokumenty\Downloads\portaudio
的portaudio标头。使用MSYS构建时,我使用./configure --prefix=/mingw
,我的MinGW目录中存在库和包含。
提前感谢任何提示。
答案 0 :(得分:0)
当我尝试调用任何portaudio函数(Pa_Initialize)时,我 得到[链接错误]
好的,链接错误通常只是缺少库。
undefined reference to `__cxa_pure_virtual'
...可以通过添加C ++标准库来修复,可能是-lstdc++
和 未定义的引用`waveOutGetNumDevs @ 0'
...可以通过添加libwinmm.a
或类似内容来修复。
来自
D:\Dokumenty\Downloads\portaudio
的portaudio标头的原因 使用
这些代表编译为libportaudio
的源代码。在构建时,它包含D:\Dokumenty\Downloads\portaudio/src/hostapi/wmme/pa_win_wmme.c
之类的源文件,这些文件引用了waveOutWrite()
之类的函数。现在您正在使用libportaudio
创建可执行文件,您必须为链接器提供解析所有这些依赖项所需的库。