PortAudio / portaudio

PortAudio is a cross-platform, open-source C language library for real-time audio input and output.
Other
1.43k stars 296 forks source link

Unable to link portaudio statically with mingw gcc #831

Closed Lucas-Marcel closed 1 year ago

Lucas-Marcel commented 1 year ago

I was able to build my project when linking it dynamically, but i can't do the same if i try to do statically, I had the same issue with libxmp, but i was able to fix it, editing it's header file, commenting out __declspec(dllexport), The issue is: I can't find anything similar in portaudio's header. These are the errors along with my build flags:

PS F:\DEVELOPMENT_LIBRARIES\raylib-master\raylib-master\ultracapped\raylib\test> gcc main.c -I. -L. -lportaudio -lxmp-lite -lraylib -lopengl32 -lgdi32 -lwinmm C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x3726): undefined reference to __imp_CoGetInterfaceAndReleaseStream' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x3796): undefined reference toimp_CoGetInterfaceAndReleaseStream' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x3b29): undefined reference to __imp_CoInitializeEx' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x3f02): undefined reference toimp_CoUninitialize' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x3f12): undefined reference to __imp_CoUninitialize' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x3ffc): undefined reference toimp_CoInitializeEx' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x4779): undefined reference to __imp_CoUninitialize' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x4b52): undefined reference toimp_CoUninitialize' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x5916): undefined reference to __imp_CoMarshalInterThreadInterfaceInStream' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x59f3): undefined reference toimp_CoGetInterfaceAndReleaseStream' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x5a7a): undefined reference to __imp_CoMarshalInterThreadInterfaceInStream' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x5b4b): undefined reference toimp_CoGetInterfaceAndReleaseStream' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x5f4f): undefined reference to __imp_CoTaskMemFree' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x8749): undefined reference toimp_CoCreateInstance' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x881a): undefined reference to __imp_CoTaskMemFree' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x8b68): undefined reference toimp_CoTaskMemFree' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x8bdb): undefined reference to __imp_PropVariantClear' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x8c64): undefined reference toimp_PropVariantClear' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x8cb1): undefined reference to __imp_PropVariantClear' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x9145): undefined reference toimp_PropVariantClear' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wasapi.c.obj):pa_win_wasapi.:(.text+0x9151): undefined reference to __imp_CoTaskMemFree' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_wdmks_utils.c.obj):pa_win_wdmks_utils.c:(.rdata$.refptr.GUID_NULL[.refptr.GUID_NULL]+0x0): undefined reference toGUID_NULL' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_coinitialize.c.obj):pa_win_coinitialize.c:(.text+0x16): undefined reference to __imp_CoInitialize' C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ./libportaudio.a(pa_win_coinitialize.c.obj):pa_win_coinitialize.c:(.text+0xed): undefined reference to__imp_CoUninitialize' collect2.exe: error: ld returned 1 exit status

Lucas-Marcel commented 1 year ago

Ok. It appears that i fixed my issue. I decided to build libportaudio as static again, but this time i built the examples. So by guess, the examples are supposed to be built staticly. In my build directory in one of the examples folder i found a file called: linklibs.rsp, i found this line of code "../libportaudio.a -lwinmm -ldsound -lole32 -luuid -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 " It turned out i only had to add these two lib flags -luuid -lole32. and i could finally compile my project.