Building and Installing Ethereum Compilers

Daniel Ellison
ConsenSys Media
Published in
5 min readMay 11, 2017

I recently created a screencast that describes the process of making two of Ethereum’s language compilers available to a developer. The work is all done at an Ubuntu command line. It starts at the point following a fresh OS install, continues through acquiring the source code and compiling it, and then describes how to install the resulting LLL and Solidity compiler binaries.

This article expands a bit on the process illustrated in the screencast. I’ll go through the same process, but I’ll provide more detail than was possible in the video.

Working environment

I’ll be using Ubuntu Server 16.04.2 LTS for this tutorial. For the most part, everything I discuss is portable aross Linux distributions except for updating the OS and installing software. Each distribution has its own package system, so you’ll have to “translate” my instructions according to your particular Linux distribution.

Setting up

We’ll start at a point immediately following the OS install. The first thing we need to do is update the system. You do this by executing apt update and apt upgrade. Note: I’m assuming this is all being executed by the root account. If you’re not logged in as root you’ll need to prepend sudo to the following apt commands.

# apt update -y && apt upgrade -y

Specifying the -y parameter avoids us being asked yes/no questions and allows the installation to continue without interruption.This can be a lengthy process so you may want to prepare a beverage of your choice while you wait. Once the system has been upgraded we need to install some software packages that are necessary to compile the Solidity source code.

# apt install -y build-essential cmake libboost-all-dev

The build-essential Ubuntu package contains almost everything you need to develop software on Linux. It makes the process of setting up a development environment on Ubuntu fairly painless. The cmake package is specified because cmake isn’t included in build-essential but it’s needed to compile the source code. The lib boost-all-dev package is included because the two Ethereum language compilers we’re building, Solidity and LLL, use the Boost C++ libraries for essential functionality.

The package installation is also a lengthy process, so you’ll probably be needing another beverage of your choice at this point.

Retrieving the source

In order to compile the Ethereum compilers we’ll need to acquire their source code. We’ll be using Git and GitHub to do this. Both the Solidity and LLL compilers are contained in a repository called solidity. They originally lived in the cpp-ethereum repository, but Solidity was extracted and placed in its own home by Bob Summerwill, and the LLL compiler came along for the ride.

To bring the Solidity source code into your environment, you would use this command:

# git clone --recursive https://github.com/ethereum/solidity.git

We need to specify --recursive because Solidity uses Git submodules; that option retrieves any submodules included in a repository. Once the command has completed, you’ll have a solidity directory in your current working directory.

Compiling the source

We’ll need to move into the new solidity directory to continue the process.

# cd solidity

Then, in order to build the source code we’ll need to create and move into a build directory.

# mkdir build && cd build

The repository has to be initialized for the compilation step. We’ll use cmake to produce the configuration files necessary to build the source.

# cmake ..

Once this is done–and it should take only seconds to complete–we can run make, which will compile the source and produce binaries for both the Solidity and LLL compilers.

# make

If you thought the software installation took a long time, you’ll be horrified at how long this compilation step takes. Seriously though, it’s really only about 10 minutes.

Installing the binaries

When the process completes, the entire Solidity repository has been compiled. If you look in the solc directory you’ll see the Solidity compiler binary, solc.

# ls -l solc

Likewise, you look in the lllc directory you’ll see the LLL compiler binary, lllc.

# ls -l lllc

Now that we have the compiled binaries we need to install them into your system. This is done by typing

# make install

Finishing up

There’s one last thing we need to do. By default, Ubuntu doesn’t include /usr/local/lib in its LD_LIBRARY_PATH environment variable. That’s the path needed to locate libraries used by the compilers. You can add this path at the command line.

# export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"

I would suggest adding that line to your ~/.bashrc file, or whatever configuration file your shell uses. Otherwise you’ll get an error when you try to execute the compilers.

Ok, both compilers are now available at your command line. Let’s invoke the Solidity compiler.

# solc --version
solc, the solidity compiler commandline interface
Version: 0.4.12-develop.2017.5.4+commit.2d89cfaa.Linux.g++

As you can see, this produces a language banner and a version string. Let’s do the same thing for LLL.

# lllc --version
LLLC, the Lovely Little Language Compiler
Version: 0.4.12-develop.2017.5.4+commit.2d89cfaa.Linux.g++

You’ll notice that both compilers have exactly the same version. That’s because the LLL compiler is contained in the Solidity repo. At some point I hope to extract LLL into its own repository with a separate release schedule.

Conclusion

This article has expanded on my screencast and is intended for those who prefer going line-by-line through the process as opposed to watching a video. I hope this proves useful. It’s not actually a complex process. But it’s a lot easier when you have a guide like this.

Read More:

An Introduction to LLL for Ethereum Smart Contract Development
Compiling an LLL Contract for the First Time
Deploying Your First LLL Contract — Part 1
Deploying Your First LLL Contract — Part 2
The Structure of an LLL Contract — Part 1
The Structure of an LLL Contract — Part 2
The Structure of an LLL Contract — Part 3

Like this piece? Sign up here for the ConsenSys weekly newsletter.

Disclaimer: The views expressed by the author above do not necessarily represent the views of Consensys AG. ConsenSys is a decentralized community with ConsenSys Media being a platform for members to freely express their diverse ideas and perspectives. To learn more about ConsenSys and Ethereum, please visit our website.

--

--