How do I build Boost from github?

The current documentation for building directly from the Git repo is at Getting Started. Basically there are some additional steps to create the include directory tree and to run the build itself. NOTE, please also make sure you use the b2 command from the cloned repo. Not whatever you might have prebuilt in your system.


To checkout latest version of Boost libraries from GitHub do the following:

  • Checkout Boost super-project (only minimum required): git clone --single-branch --branch master --depth=1 https://github.com/boostorg/boost.git.
  • cd boost/
  • Checkout all the submodules (only minimum required): git submodule update --init --recursive --remote --no-fetch --depth=1.

If an error like following occured:

Cloning into 'libs/predef'...
remote: Counting objects: 243, done.
remote: Compressing objects: 100% (163/163), done.
remote: Total 243 (delta 128), reused 126 (delta 70), pack-reused 0
Receiving objects: 100% (243/243), 142.82 KiB | 209.00 KiB/s, done.
Resolving deltas: 100% (128/128), done.
Checking connectivity... done.
fatal: Needed a single revision
Unable to find current origin/master revision in submodule path 'libs/predef'

then use script (reget.bash):

#! /usr/bin/env bash -vex

rm -rf $3/$1 .git/modules/$1
git clone --depth=1 --branch=$2 --single-branch --separate-git-dir .git/modules/$1 https://github.com/boostorg/$1 $3/$1

where $1 is predef, $2 is master, $3 is libs, i.e. run bash reget.bash predef master libs.

An error can occur many times for different submodules, just use above script to clean up unrecoverable git error and to checkout latest commit for failed submodule. Then reuse git submodule update --init --recursive --remote --no-fetch --depth=1.

After complete checking out of all the submodules, build b2 executable. For clang it looks like:

export CC=clang
export CFLAGS="-march=native -Ofast"
export CXX=clang++
export CXXFLAGS="-march=native -Ofast"

bash bootstrap.sh --with-toolset=clang

You have obtained b2 executable. Use it to build whole Boost:

sudo ./b2 -j`nproc` toolset=clang --build-dir=/tmp/build-boost --without-mpi install

ADDITIONAL:

If you want to clone only HEAD of boost itself and HEADS of all the its submodules, then you may use following Lua script (tested on https://github.com/boostorg/boost.git repository):

-- mkdir boost ; cd boost ; lua ../git-submodules-clone-HEAD.lua https://github.com/boostorg/boost.git .
local module_url = arg[1] or 'https://github.com/boostorg/boost.git'
local module = arg[2] or module_url:match('.+/([_%d%a]+)%.git')
local branch = arg[3] or 'master'
function execute(command)
    print('# ' .. command)
    return os.execute(command)
end
-- execute('rm -rf ' .. module)
if not execute('git clone --single-branch --branch master --depth=1 ' .. module_url .. ' ' .. module) then
    io.stderr:write('can\'t clone repository from ' .. module_url .. ' to ' .. module .. '\n')
    return 1
end
-- cd $module ; git submodule update --init --recursive --remote --no-fetch --depth=1
execute('mkdir -p ' .. module .. '/.git/modules')
assert(io.input(module .. '/.gitmodules'))
local lines = {}
for line in io.lines() do
    table.insert(lines, line)
end
local submodule
local path
local submodule_url
for _, line in ipairs(lines) do
    local submodule_ = line:match('^%[submodule %"([_%d%a]-)%"%]$')
    if submodule_ then
    submodule = submodule_
    path = nil
    submodule_url = nil
    else
    local path_ = line:match('^%s*path = (.+)$')
    if path_ then
        path = path_
    else
        submodule_url = line:match('^%s*url = (.+)$')
    end
    if submodule and path and submodule_url then
        -- execute('rm -rf ' .. path)
        local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
        -- execute('rm -rf ' .. git_dir)
        execute('mkdir -p $(dirname "' .. git_dir .. '")')
        if not execute('git clone --depth=1 --single-branch --branch=' .. branch .. ' --separate-git-dir ' .. git_dir .. ' ' .. module_url .. '/' .. submodule_url .. ' ' .. module .. '/' .. path) then
            io.stderr:write('can\'t clone submodule ' .. submodule)
            return 1
        end
        path = nil
        submodule_url = nil
    end
    end
end

Tags:

Boost