Hello Fred,
Nice job, How did you go about compiling it?
If I (or someone else) ever need to reproduce it.
I need to understand which parameters and windows backend(MME,WASAPI,WDMKS or ASIO) it's was used for the compilation.
Regards,
I did cross-compile from Linux 64 to Windows 64/32.
You may take a look at https://github.com/fredvs/portaudio-static there is the script cross_compile_portaudio_win32-64.sh, it should work out-of-the-box.
Copy the script in a new folder (ex static-portaudio), set the script as executable and run it:
cd static-portaudio
chmod +x cross_compile_win_32-64.sh
./cross_compile_portaudio_win32-64.sh
You will need to install this before running the script:
sudo apt update
sudo apt install -y mingw-w64 cmake git build-essential
Maybe it is possible to create the static lib with asio included directly from a Windows system but I did not try, I feel it more easy to use cross-compilation from linux.
About using the static lib in fpc, I was able to do it for linux, it works great but I did not try to do it for windows (in fact I did try to do it with wine on linux but I fail, maybe do it directly from windows will be easier).
First paste libportaudio.a in the root directory of the project and this is the command I used to compìle it on linux:
fpc -FUunits -Fl. -k"--copy-dt-needed-entries" -k"--start-group" -k"-lportaudio" -k"-lpthread" -k"-lc" -k"--end-group" portaudio_demo.pas
For windows I did not try, I dont have a Windows machine at the moment but you may use the binary of static libportaudio.a from my site.
Good luck.
Fred
Thanks Fred for the detail, I see 2 folders on archive "libportaudio-static-windows" and "windows-static" with 2 differents file size? also I noticed you don't use -Xe.
I tried without using linklib using this command :
I created build.bat using :
@echo off
set FPC=C:\fpcupdeluxe\fpc\bin\x86_64-win64\fpc.exe
if not exist units mkdir units
%FPC% ^
-B ^
-MObjFPC ^
-Sh ^
-Twin64 ^
-Px86_64 ^
-FUunits ^
-Fu. ^
-FlC:\msys64\home\dev\portaudio\build-ninja ^
-FlC:\msys64\mingw64\lib ^
-FlC:\msys64\mingw64\lib\gcc\x86_64-w64-mingw32\16.1.0 ^
-k"--start-group" ^
-k"-lstdc++" ^
-k"-lsupc++" ^
-k"-lgcc_eh" ^
-k"-lgcc" ^
-k"-lwinpthread" ^
-k"-lmingwex" ^
-k"-lmoldname" ^
-k"-lmsvcrt" ^
-k"-lwinmm" ^
-k"-lole32" ^
-k"-loleaut32" ^
-k"-luuid" ^
-k"-lsetupapi" ^
-k"-ladvapi32" ^
-k"-lavrt" ^
-k"-lkernel32" ^
-k"-luser32" ^
-k"--end-group" ^
test_portaudio_static.lpr
pause
but I got error without $LINKLIB in Portaudio wrapper :
"Free Pascal Compiler version 3.3.1-20107-g8594e9ad47-dirty [2026/04/28] for x86_64
Copyright (c) 1993-2026 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling test_portaudio_static.lpr
Compiling uportaudiostatic.pas
Linking test_portaudio_static.exe
test_portaudio_static.lpr(30,1) Error: Undefined symbol: strncpy (first seen in libportaudio.a(pa_front.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_GlobalAlloc (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_GlobalFree (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_Sleep (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_QueryPerformanceFrequency (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_QueryPerformanceCounter (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_timeGetTime (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_FormatMessageW (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_WideCharToMultiByte (first seen in libportaudio.a(pa_win_util.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutWrite (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutGetErrorTextW (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInAddBuffer (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInGetErrorTextW (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_SetEvent (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutReset (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInReset (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_WaitForSingleObject (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_CloseHandle (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutOpen (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInOpen (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutUnprepareHeader (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInUnprepareHeader (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInPrepareHeader (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutPrepareHeader (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: ___chkstk_ms (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutClose (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInClose (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_GetLastError (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_CreateEventW (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutPause (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_ResetEvent (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp__beginthreadex (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_SetThreadPriority (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInStart (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutRestart (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_WaitForMultipleObjects (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutGetPosition (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInMessage (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutMessage (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInGetNumDevs (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutGetNumDevs (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveInGetDevCapsW (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_waveOutGetDevCapsW (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_GetEnvironmentVariableA (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: memcpy (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: memset (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: atoi (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: strlen (first seen in libportaudio.a(pa_win_wmme.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_timeEndPeriod (first seen in libportaudio.a(pa_win_ds.c.obj))
test_portaudio_static.lpr(30,1) Error: Undefined symbol: __imp_SetWaitableTimer (first seen in libportaudio.a(pa_win_ds.c.obj))
test_portaudio_static.lpr(30,1) Fatal: There were 50 errors compiling module, stopping
Fatal: Compilation aborted
Error: C:\fpcupdeluxe\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode"
with LinkLib, I execute build.bat but no detail:
{$IFDEF MSWINDOWS}
// PortAudio statique
{$LINKLIB libportaudio.a}
// C++ for ASIO
{$LINKLIB libstdc++.a}
{$LINKLIB libsupc++.a}
{$LINKLIB libgcc_eh.a}
{$LINKLIB libgcc.a}
// Threads MinGW
{$LINKLIB libwinpthread.a}
// Runtime C MinGW
{$LINKLIB libmingw32.a}
{$LINKLIB libmingwex.a}
{$LINKLIB libmoldname.a}
{$LINKLIB libmsvcrt.a}
// Windows
{$LINKLIB winmm}
{$LINKLIB ole32}
{$LINKLIB oleaut32}
{$LINKLIB uuid}
{$LINKLIB setupapi}
{$LINKLIB advapi32}
{$LINKLIB avrt}
{$LINKLIB kernel32}
{$LINKLIB user32}
{$ENDIF}
"
Free Pascal Compiler version 3.3.1-20107-g8594e9ad47-dirty [2026/04/28] for x86_64
Copyright (c) 1993-2026 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling test_portaudio_static.lpr
Compiling uportaudiostatic.pas
Linking test_portaudio_static.exe
Error: C:\fpcupdeluxe\fpc\bin\x86_64-win64\ppcx64.exe returned an error exitcode"