| 1 |
HOW TO COMPILE JACK ON WINDOWS/MINGW |
| 2 |
==================================== |
| 3 |
|
| 4 |
Rev. 1 - 2019-09-01 - First version |
| 5 |
Rev. 2 - 2019-09-18 - Include contributions from @Schroedingers-Cat |
| 6 |
Rev. 3 - 2019-12-14 - Include contributions from @Schroedingers-Cat |
| 7 |
Rev. 4 - 2020-11-27 - Rename, update intro and JackRouter build instructions |
| 8 |
|
| 9 |
|
| 10 |
Introduction |
| 11 |
------------ |
| 12 |
|
| 13 |
This guide was originally called "How to compile JACK using WAF and MinGW" |
| 14 |
and later renamed to "How to compile JACK on Windows/MinGW" to avoid confusion |
| 15 |
with the official way of building JACK for Windows, which is cross-compiling |
| 16 |
on Linux. That should be considered the only officially supported method now. |
| 17 |
|
| 18 |
Latest binary releases can be found here: https://jackaudio.org/downloads/ |
| 19 |
JackRouter here: https://github.com/jackaudio/jack-router/tree/main/binaries |
| 20 |
|
| 21 |
JACK is primarily targeted at Unix systems and thus the required toolchain is |
| 22 |
Unix-centric. So the majority of the guide is actually about setting up the |
| 23 |
required build tools. Once done, the build process itself does not differ much |
| 24 |
from that found on other platforms. |
| 25 |
|
| 26 |
The information here can be of interest to anyone wishing to contribute to the |
| 27 |
development of Windows specific code in JACK, and wants to avoid double booting, |
| 28 |
VMs, etc. That can be particularly helpful when it comes to debug or testing. |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
Creating the development environment |
| 33 |
------------------------------------ |
| 34 |
|
| 35 |
This guide uses MSYS2 as the toolchain, it can be found at https://www.msys2.org/ |
| 36 |
It comes as a handy installer called msys2-x86_64-{version}.exe. Once installed: |
| 37 |
|
| 38 |
- Open "MSYS2 MinGW 64-bit terminal" from the MSYS2 start menu shortcuts |
| 39 |
|
| 40 |
- Upgrade base MSYS2 packages |
| 41 |
|
| 42 |
pacman -Suy |
| 43 |
|
| 44 |
It is possible pacman ends with the following banner: |
| 45 |
|
| 46 |
warning: terminate MSYS2 without returning to shell and check for updates again |
| 47 |
warning: for example close your terminal window instead of calling exit |
| 48 |
|
| 49 |
In such case close the MSYS2 window, re-open, and run pacman -Suy again. |
| 50 |
|
| 51 |
- Install required packages |
| 52 |
|
| 53 |
pacman -S mingw-w64-x86_64-toolchain patch autoconf make \ |
| 54 |
gettext-devel automake libtool pkgconfig p7zip unzip git python |
| 55 |
|
| 56 |
- Replace the GCC compiler with a version configured for SJLJ exceptions, as |
| 57 |
instructed by the original Windows build instructions (windows/README) |
| 58 |
|
| 59 |
Prebuilt binaries can be found at |
| 60 |
https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/ |
| 61 |
|
| 62 |
Look for "x86_64-posix-sjlj" under "MinGW-W64 GCC-{version}", the file should be |
| 63 |
called x86_64-{version}-release-posix-sjlj-rt_v6-rev0.7z |
| 64 |
|
| 65 |
Or just download from a direct link (GCC 8.1.0): |
| 66 |
|
| 67 |
wget https://downloads.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/sjlj/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7z |
| 68 |
|
| 69 |
Once downloaded: |
| 70 |
|
| 71 |
p7zip -d x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7z |
| 72 |
|
| 73 |
That will decompress to a folder called mingw64 in the working directory. |
| 74 |
Now replace the files from the previous mingw-w64-x86_64-toolchain package |
| 75 |
installation: |
| 76 |
|
| 77 |
mv /mingw64 /mingw64.bak -> backup original |
| 78 |
rm /mingw64 -> see explanation below |
| 79 |
mv mingw64 / -> sjlj toolchain |
| 80 |
|
| 81 |
The first step results in a new file called mingw64 file being created in /. The |
| 82 |
file is not visible to the Windows File Explorer when inspecting C:\msys64, so |
| 83 |
it is probably an artifact and safe to delete it in the second step. Otherwise |
| 84 |
the last mv step will fail with: |
| 85 |
|
| 86 |
mv: cannot overwrite non-directory '/mingw64' with directory 'mingw64' |
| 87 |
|
| 88 |
An alternate solution consists in closing the MSYS2 window and replicating the |
| 89 |
above procedure using the File Explorer. The following assumes the toolchain 7z |
| 90 |
file was decompressed to the home directory: |
| 91 |
|
| 92 |
Rename C:\msys64\mingw64 to C:\msys64\mingw64.bak |
| 93 |
Move C:\msys64\home\{username}\mingw64 to C:\msys64 |
| 94 |
|
| 95 |
Make sure gcc runs and it is the expected version: |
| 96 |
|
| 97 |
$ gcc --version |
| 98 |
gcc.exe (x86_64-posix-sjlj-rev0, Built by MinGW-W64 project) {version} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
Preparing JACK dependencies |
| 103 |
--------------------------- |
| 104 |
|
| 105 |
There are prebuilt MinGW binaries for all the libraries that can be installed |
| 106 |
using the pacman package manager, but since we are using a compiler that is not |
| 107 |
the default version shipped by MinGW, it seems better idea to build from source |
| 108 |
to avoid any linker and runtime issues. A good technical explanation and/or |
| 109 |
evidence for this statement is currently missing from this guide. |
| 110 |
|
| 111 |
Fortunately there are PKGBUILD files for doing so together with a nice guide at |
| 112 |
https://github.com/msys2/MINGW-packages |
| 113 |
|
| 114 |
git clone https://github.com/msys2/MINGW-packages.git |
| 115 |
|
| 116 |
Before building libraries, adjust the includes path: |
| 117 |
|
| 118 |
export C_INCLUDE_PATH=/mingw64/include |
| 119 |
|
| 120 |
The basic procedure for building and installing libraries is: |
| 121 |
|
| 122 |
cd MINGW-packages/mingw-w64-{libname} |
| 123 |
MINGW_INSTALLS=mingw64 makepkg-mingw -sLf |
| 124 |
pacman -U mingw-w64-{libname}-{suffix}.pkg.tar.xz |
| 125 |
|
| 126 |
Repeat the procedure for each library listed below replacing {libname} with the |
| 127 |
appropriate name and {suffix} with whatever the above process creates. Keep the |
| 128 |
recommended build order, for example libsamplerate depends on libsndfile, and |
| 129 |
libsystre depends on libtre-git. libsystre is a wrapper around libtre that |
| 130 |
allows including <regex.h> later. |
| 131 |
|
| 132 |
Some libraries like libsndfile and libsamplerate will ask for installing extra |
| 133 |
dependencies, it is ok to do so. |
| 134 |
|
| 135 |
For low latency audio it is recommended to build portaudio with ASIO support, so |
| 136 |
the Steinberg ASIO SDK should be manually downloaded beforehand. It can be found |
| 137 |
at https://www.steinberg.net/en/company/developers.html. The waf script will |
| 138 |
later check if the SDK is present at /opt/asiosdk |
| 139 |
|
| 140 |
wget https://www.steinberg.net/asiosdk -O /tmp/asiosdk.zip |
| 141 |
unzip /tmp/asiosdk.zip -d /tmp |
| 142 |
mkdir /opt <- MinGW does not create /opt during installation |
| 143 |
mv /tmp/asiosdk_{version}_{date} /opt/asiosdk |
| 144 |
|
| 145 |
The description file in portaudio (MINGW-packages/mingw-w64-portaudio/PKGBUILD) |
| 146 |
needs to be patched so configure is called with the necessary flags for ASIO: |
| 147 |
|
| 148 |
--with-asiodir=/opt/asiosdk <- new option |
| 149 |
--with-winapi=wmme,directx,wasapi,vdmks,asio <- append 'asio' to existing |
| 150 |
|
| 151 |
Both static and shared library versions of portaudio are built. To prevent |
| 152 |
errors while building the shared version or recompiling static, also insert the |
| 153 |
following lines in PKGBUILD after the first make call (around line 60) and after |
| 154 |
second make (around line 70): |
| 155 |
|
| 156 |
find /opt/asiosdk -name "*.lo" -type f -delete |
| 157 |
find /opt/asiosdk -name "*.o" -type f -delete |
| 158 |
|
| 159 |
Finally here is the list of libraries to build: |
| 160 |
|
| 161 |
db |
| 162 |
libsndfile |
| 163 |
libsamplerate |
| 164 |
libtre-git |
| 165 |
libsystre |
| 166 |
portaudio |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
Compiling JACK |
| 171 |
-------------- |
| 172 |
|
| 173 |
- Clone repo |
| 174 |
|
| 175 |
git clone https://github.com/jackaudio/jack2 |
| 176 |
|
| 177 |
- Build and install |
| 178 |
|
| 179 |
cd jack2 |
| 180 |
./waf configure --prefix=/opt/jack && ./waf -p install |
| 181 |
|
| 182 |
The resulting files can be found at /c/opt/jack/bin, or C:\msys64\opt\jack\bin |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
Compiling JackRouter |
| 187 |
-------------------- |
| 188 |
|
| 189 |
Source code for JackRouter is not considered part of JACK anymore so you need to |
| 190 |
clone an additional repository: |
| 191 |
|
| 192 |
git clone https://github.com/jackaudio/jack-router |
| 193 |
|
| 194 |
Visual Studio with MFC support is needed to build the included JackRouter VS |
| 195 |
project. The project was tested to successfully generate a 64bit version of |
| 196 |
JackRouter.dll using Visual Studio 2017 and 2019. MFC support can be added from |
| 197 |
the VS installer, by selecting Workloads/Visual C++ build tools/Visual C++ MFC |
| 198 |
for x86 and x64 (valid for VS 2017). |
| 199 |
|
| 200 |
Once ready, just open and build the project |
| 201 |
|
| 202 |
win/JackRouter.sln |
| 203 |
|
| 204 |
Notes: |
| 205 |
|
| 206 |
- The project assumes the needed ASIO SDK is located in C:\Program Files\asiosdk |
| 207 |
you can simply copy the SDK from the MinGW JACK installation, i.e. from |
| 208 |
C:\msys64\opt to C:\Program Files |
| 209 |
- Links against C:\Program Files\JACK2\lib\libjack64.dll.a which is the libjack |
| 210 |
version installed by the official installer. You will have to update that path |
| 211 |
so it points to the jack.dll.a created by the MinGW build instead. |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
Running and distributing |
| 216 |
------------------------ |
| 217 |
|
| 218 |
!! This section is kept for historical reasons. The official JACK for Windows |
| 219 |
build method includes the necessary steps to create a installer. !! |
| 220 |
|
| 221 |
An automated installation process should copy files to two destinations. One for |
| 222 |
the JACK server binary and standalone tools, and another for the client library. |
| 223 |
The latter is needed by JACK enabled applications in order to be able to connect |
| 224 |
to the server. |
| 225 |
|
| 226 |
- Create a directory named C:\Program Files\Jack (can be anything else) |
| 227 |
- Copy all files in C:\msys64\opt\jack\bin to C:\Program Files\Jack |
| 228 |
- Copy the following DLLs from C:\msys64\mingw64\bin to C:\Program Files\Jack, |
| 229 |
these are dependencies for the JACK server and tools: |
| 230 |
|
| 231 |
libstdc++-6.dll |
| 232 |
libdb-6.0.dll |
| 233 |
libsndfile-1.dll |
| 234 |
libsamplerate-0.dll |
| 235 |
libportaudio-2.dll |
| 236 |
libgcc_s_sjlj-1.dll |
| 237 |
libwinpthread-1.dll |
| 238 |
libtre-5.dll |
| 239 |
libsystre-0.dll |
| 240 |
|
| 241 |
- Copy and rename the following files from C:\msys64\opt\jack\bin to C:\Windows |
| 242 |
to make libjack available to clients: |
| 243 |
|
| 244 |
libjackserver-0.dll -> libjackserver64.dll |
| 245 |
libjack-0.dll -> libjack64.dll |
| 246 |
|
| 247 |
- Copy the following files from C:\msys64\mingw64\bin to C:\Windows, these are |
| 248 |
dependencies for libjack. C:\Windows is the directory the current official JACK |
| 249 |
1.9.11 binary installer targets, a better solution should be devised to avoid |
| 250 |
cluttering the Windows directory: |
| 251 |
|
| 252 |
libgcc_s_sjlj-1.dll |
| 253 |
libwinpthread-1.dll |
| 254 |
libtre-5.dll |
| 255 |
libsystre-0.dll |
| 256 |
|
| 257 |
- Copy JackRouter.dll from windows\JackRouter\Release64 to C:\Program Files\Jack |
| 258 |
This allows non-JACK applications to connect to the server through a special |
| 259 |
ASIO driver that routes audio to JACK instead of a physical audio device. |
| 260 |
Also copy libjack-0.dll from C:\msys64\mingw64\bin to C:\Program Files\Jack |
| 261 |
because JackRouter depends on libjack but will check for libjack-0.dll instead |
| 262 |
of the system-wide libjack64.dll previously copied to C:\Windows. Once done, |
| 263 |
JackRouter needs to be registered: |
| 264 |
|
| 265 |
regsvr32 JackRouter.dll |
| 266 |
|
| 267 |
Tested working clients: |
| 268 |
Ardour |
| 269 |
Bitwig Studio |
| 270 |
QJackCtl |
| 271 |
JackRouter |
| 272 |
|
| 273 |
Example of starting the JACK server including MIDI support for a Focusrite USB |
| 274 |
audio device using ASIO: |
| 275 |
jackd -R -S -X winmme -d portaudio -p 32 -r 48000 -d "ASIO::Focusrite USB ASIO" |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
Development tools and links |
| 280 |
--------------------------- |
| 281 |
|
| 282 |
http://www.dependencywalker.com/ |
| 283 |
https://docs.microsoft.com/en-us/sysinternals/downloads/procmon |
| 284 |
https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/gflags |
| 285 |
https://blogs.msdn.microsoft.com/junfeng/2006/11/20/debugging-loadlibrary-failures/ |
| 286 |
https://stackoverflow.com/questions/15852677/static-and-dynamic-shared-linking-with-mingw |
| 287 |
https://github.com/EddieRingle/portaudio/blob/master/src/hostapi/asio/ASIO-README.txt |