要从GitHub检出最新版本的 Boost 库,请执行以下操作:
- 检出Boost超级项目(仅需最低限度):
git clone --single-branch --branch master --depth=1 https://github.com/boostorg/boost.git
。
cd boost/
- 检出所有子模块(仅需最低限度):
git submodule update --init --recursive --remote --no-fetch --depth=1
。
如果出现以下错误:
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'
然后使用脚本 (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
其中 $1
是 predef
,$2
是 master
,$3
是 libs
,也就是运行 bash reget.bash predef master libs
可能会因为不同的子模块出现多次错误,请使用上述脚本清理无法恢复的git错误,并检查失败的子模块的最新提交。然后重用 git submodule update --init --recursive --remote --no-fetch --depth=1
在完成所有子模块的检出后,构建 b2
可执行文件。对于 clang,它看起来像这样:
export CC=clang
export CFLAGS="-march=native -Ofast"
export CXX=clang++
export CXXFLAGS="-march=native -Ofast"
bash bootstrap.sh --with-toolset=clang
您已经获得了b2
可执行文件。使用它来构建整个Boost:
sudo ./b2 -j`nproc` toolset=clang --build-dir=/tmp/build-boost --without-mpi install
额外信息:
如果您只想克隆boost本身的HEAD
和其所有子模块的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
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
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
local git_dir = module .. '/.git/modules/' .. path:match('^.-/(.+)$')
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
boost-1.55
分支/标签名称。当然,如果您想要不同的分支,请请求它,例如BOOST_VER=develop
将所有子项目切换到develop
分支。但是,如果boost-1.55
不是boost-1.55.0
的拼写错误,并且您的克隆版本中没有它,我建议检查您的克隆版本(根据需要更新或重新克隆)。 - sehe