Ch.5 Setting up SML# programming environment

§ 5.3. Installing SML#

The SML# version 2.0.0 works on one of the following platforms.

  • Linux (x86, or amd64 with 32 bit development environment)

  • Mac OS X (Intel version)

SML# compiler requires the following libraries.

  • GNU Multiple Precision Arithmetic (GMP)

  • LLVM 3.4

GMP is a free software distributed under LGPL(GNU Lesser General Public License). LLVM is a open-source software distributed under a BSD-style license. SML# compiler will be linked with all of the above libraries. The executable file of any user program compiled by the SML# compiler is linked with GMP. Since these libraries are not included in the SML# distribution package, you need to install it before installing SML#.

Note that LLVM version 3.4 is exactly required. With older version of LLVM than 3.4, compilation of SML# shall fail. Since LLVM provide different APIs in different versions, we cannot make sure whether SML# can compile with newer version of LLVM than 3.4 or not.

Below, we show the details of SML# installation steps for each of the supported operating systems.

§ 5.3.1. Mac OS X

We prepare an SML# Portfile. After setting up MacPorts,download the SML# Portfile, set it up as a local Portfile, and do port install smlsharp. We show some more details below.

  1. Consult and set up MacPorts.

  2. Create a directory and set it as a local Portfile repository. For example, if you plan to put local Portfiles in /opt/var/macports/sources/local, create the directory and write the following line

    file:///opt/var/macports/sources/local [nosync]

    in the file /opt/etc/macports/sources.conf. For more details, consult:

  3. Extract the local Portfile repository in the repository directory as:

    $ cd /opt/var/macports/sources/local
    $ unzip

    After this step, you will see lang/smlsharp/Portfile.

  4. Execute portindex command on the local Portfile repository directory as:

    $ portindex /opt/var/macports/sources/local
  5. The above steps should have set SML# package to MacPorts. You can now install SML# by port command as:

    $ port install smlsharp

SML# version 2.0.0 only support 32 bit mode on x86 architecture. So in Mac OS X 10.6 or later version with 64 bit MacPorts, GMP library must be a 32 bit version or a universal binary that include a 32 bit version. This dependency should be automatically resolved when you install SML# by port command. To resolve this dependency, port command may re-build 64-bit GMP to make it as a universal binary.

§ 5.3.2. Ubuntu

.deb packages for both i386 and amd64 version are available. Download it and install it by dpkg command, then SML# compiler is available on your system. We show some more details below.

  1. Do dpkg --install with the downloaded .deb package. If other packages required for SML# has not been installed on your system, dpkg command fails and produces an error message with a list of the required packages. In this case, you need to install the required package by apt-get command and do dpkg --install command again. For example, on i386 Debian GNU/Linux, do the following commands.

    $ sudo dpkg --install smlsharp-2.0.0-1_i386.deb

Note that these .deb packages are not a part of an official release of Debian or Ubuntu system. Unlike official packages, they do not include any signature of package maintainer. Also note that the .deb package for amd64 only includes 32 bit version of SML# compiler. It does not produce any 64 bit code.

§ 5.3.3. Debian GNU/Linux

Debian GNU/Linux contains SML# as a part of official distribution. You can install SML# through aptitude command. For example,

$ sudo aptitude install smlsharp

If you want to use the latest version of SML# that is not available from the Debian official distribution, compile SML# from source code.

§ 5.3.4. Building from the source

For Linux and other systems, you need to build from the SML# source distribution. To do this, the following tools and libraries are required:

  1. GNU binutils(GNU Binary Utilities),

  2. C and C++ compiler (gcc or clang),

  3. make (GNU make is recommended),

  4. GMP library and its header files, and

  5. LLVM 3.4.

In a 64 bit OS, these tools and libraries must be of 32 bit version.

If your 64 bit OS does not provide a 32 bit GMP and LLVM, you need to build those of 32 bit version from the source. See official documents of GMP and LLVM for details of this procedure. For your information, we roughly present how to compile them at the time when we write this document.

  • GMP

    Get the GMP source from GMP web page, and configure it with ABI=32 option as in the following:

    $ ./configure ABI=32
    $ make
    $ make install

    If your system have an official distribution of GMP, then you may want to specify the install location of the 32 bit version through --prefix option.

  • LLVM Get the LLVM 3.4 source package llvm-3.4.src.tar.gz from LLVM web page, and configure it with CC='gcc -m32' and CXX='g++ -m32' options as in the following:

    $ ./configure CC='gcc -m32' CXX='g++ -m32'
    $ make
    $ make install

    Similar to GMP, you may want to specify the install location through --prefix option.

With these preparation, SML# can be build in the following steps.

  1. Download the source distribution from:\version{}.tar.gz. The latest version of the source package is also available from

  2. Select an SML# source directory and extract the tar archive there.

  3. Select an SML# installation destination directory. Let prefix be the path to the directory.

  4. In the SML# source directory, execute configure script. In a 64 bit OS,set CC, C++ and LD to a 32 bit C/C++ compiler and a 32 bit linker, respectively. To enable multithread (POSIX thread) support, give --enable-thread switch to ./configure script.

    In i386 Linux, you would do the following:

    $ ./configure --prefix=prefix

    In amd64 Linux:

    $ ./configure CC='gcc -m32' CXX='g++ -m32' LD='ld -m elf_i386' --prefix=prefix
  5. Do the following:

    $ make
    $ make install

The following files are installed.

  1. smlsharp command at prefix/bin/smlsharp

  2. smlformat command at prefix/bin/smlformat

  3. smllex command at prefix/bin/smllex

  4. smlyacc command at prefix/bin/smlyacc

  5. library files in the prefix/lib/smlsharp/ directory.

If successful, you can invoke SML# by typing:

$ prefix/bin/smlsharp

Some hints:

  • This process compiles all the source files including those of tools, which takes some time. If you have a CPU with n cores and use GNU make, then try to give -jm (mn) switch to make command for parallel processing, where m indicate the degree of parallelism.