Solarian Programmer

My programming ramblings

Building SBCL - Steel Bank Common Lisp on Windows

Posted on August 20, 2019 by Paul

In this article, I will show you how to build the latest stable version of SBCL - Steel Bank Common Lisp on Windows. The officially provided binary of SBCL for Windows is typically older than the latest stable version, so I wrote this tutorial in the hope that it will be useful for people that want to use the latest version of SBCL. The article will also be useful for people that want to customize the installation of SBCL, for example you could build SBCL with more or less memory than the default 1GB that is allocated for the 64 bits version.

In order to build SBCL we’ll need another Common Lisp compiler, one will typically use an older version of SBCL and a C compiler with the GNU binutils. For this article I will use the latest provided SBCL Windows 64 bits binary which is at version 1.4.14 at the time of this writing. For the C compiler and GNU binutils I will use the MSYS2 distribution. The advantage of this approach is that you will be able to move the resulting SBCL binary to any Windows machine.

The article consists of three parts:

Install MSYS2 and the GCC toolchain

Start by downloading the latest installer of MSYS2. I recommend the 64 bits version, named msys2-x86_64-yyyy if you have a 64 bits Windows installation. Once the download is finished, start the installer and accept the defaults, you should end up with an MSYS command prompt window.

In the MSYS2 command prompt window or terminal, write:

1 pacman -Syu

and respond with Y when asked for confirmation. The above command will update the installation. Close the console window when the update is finished and reopen it from the Windows start menu. Be sure to pick the entry that reads MSYS2 MSYS from the start menu. Repeat the above command to finalize the update process:

1 pacman -Syu

Once the above is finished, we are ready to install the GCC toolchain:

1 pacman -S mingw-w64-x86_64-toolchain

Next, install the bzip2 utility:

1 pacman -S bzip2

Close the MSYS2 command prompt by writing:

1 exit

Install the official SBCL binary

Go to the SBCL download page and get the latest Windows 64 bits binary. At the time of this writing, latest SBCL binary is 1.4.14. This is a typical Windows installer.

Be sure to modify the default install location in order to not contain any spaces and to disable the add SBCL to the Windows PATH:

SBCL installer customization

As you can see, from the above image, I’ve chosen to install SBCL to C:\DEV\SBCL-1.4.4. Feel free to use a different location, as long as there are no spaces in the install path. I’ve also disabled the add SBCL to the Windows PATH and the creation of the SBCL_HOME environment variable, this is necessary in order to not interfere with the SBCL build from the next part of the tutorial.

After the above customization, you can accept all the installer defaults.

Building latest SBCL

Use the Windows start menu to open a MinGW 64 command prompt, pick the entry that reads MSYS2 MinGW 64-bit and download the SBCL source file:

1 wget http://prdownloads.sourceforge.net/sbcl/sbcl-1.5.5-source.tar.bz2?download -O sbcl-1.5.5-source.tar.bz2

Once the download is finished, extract the archive:

1 bzip2 -vfd sbcl-1.5.5-source.tar.bz2
2 tar xfv sbcl-1.5.5-source.tar
3 rm sbcl-1.5.5-source.tar

Next, temporarily add to the path the official SBCL binary and create the SBCL_HOME environment variable:

1 export PATH=/C/DEV/SBCL-1.4.4:$PATH
2 export SBCL_HOME=/C/DEV/SBCL-1.4.4

Please note, that in the above I assumed that you’ve installed the official SBCL binary to C:\DEV\SBCL-1.4.4. If you’ve used a different install location, modify the above command accordingly.

Next, create a temporary environment variable named GNUMAKE that points to the mingw32-make utility:

1 export GNUMAKE=mingw32-make

At this point, we are ready to build the latest SBCL. For simplicity, I will install SBCL to C:\SBCL-1.5.5. Again feel free to use a different location as long as you have no spaces in the install path, you will also need to modify the next commands accordingly if you want to use a different install path:

1 cd sbcl-1.5.5
2 sh make.sh --prefix=/C/SBCL-1.5.5

If there are no build errors, you can install SBCL:

1 unset SBCL_HOME
2 sh install.sh

Next, you can optionally add the newly built SBCL to the MSYS2 path:

1 cd ~
2 echo 'export PATH=/C/SBCL-1.5.5/bin:$PATH' >> .bashrc
3 echo 'export SBCL_HOME=/C/SBCL-1.5.5/lib/sbcl' >> .bashrc
4 . .bashrc

With the above you should have the sbcl available from a MinGW command prompt.

It is probably easier and more portable to create a Windows batch file that sets the above environment variables. Create a text file named open_cmd.bat in C:\SBCL-1.5.5 and copy the next commands to it:

1 set PATH=./bin;%PATH%
2 set SBCL_HOME=./lib/sbcl
3 cmd /k cls

The above will let you double click on open_cmd.bat which will temporarily add SBCL to the PATH and open a command window in which you can use the sbcl executable. It is also possible to add the above to the Windows PATH permanently, but I suggest to use the batch file approach in order to not mess the Windows PATH.

If you want to get a SBCL REPL double click on open_cmd.bat and write sbcl. If you have a .lisp file, e.g. my_script.lisp, that you want to run, you could use:

1 sbcl --script my_script.lisp

If you want to copy the resulting binary to a different Windows machine, simply copy the SBCL-1.5.5 folder to the new machine. No need to install MSYS2 to the new machine.


Show Comments