我该如何从github上构建Boost?

24

我从Github上克隆了最新的Boost源代码到主分支。 我尝试构建它,但失败了。

$ ./bootstrap.sh 
  ./bootstrap.sh: line 188: ./tools/build/src/engine/build.sh: No such file or directory
  -n Building Boost.Build engine with toolset ... 

  Failed to build Boost.Build build engine
  Consult 'bootstrap.log' for more details

bootstrap.log的内容:

1 ./bootstrap.sh: 第218行:cd: ./tools/build/src/engine: 没有那个文件或目录


问题:
我知道没有 ./tools/build/src/engine,我该怎么解决?我还注意到:

-n 使用工具集构建Boost.Build引擎...

但是,bootstrap.sh没有-n选项。


我的开发环境:MacOS X10.9 Xcode5.1


可能是如何安装模块化Boost?的重复问题。 - sehe
@sehe,谢谢。我尝试了你在那篇帖子上的回答,但是我遇到了错误:“pathspec 'boost-1.55.0' did not match any file(s) known to git.” 我可以构建boost-1.55,但是我需要构建最新的代码。 - user001
这意味着您所在的存储库中没有boost-1.55分支/标签名称。当然,如果您想要不同的分支,请请求它,例如 BOOST_VER=develop 将所有子项目切换到develop分支。但是,如果boost-1.55不是boost-1.55.0的拼写错误,并且您的克隆版本中没有它,我建议检查您的克隆版本(根据需要更新或重新克隆)。 - sehe
https://github.com/boostorg/wiki/wiki/Getting-Started%3A-Overview - herr_azad
4个回答

17

从Git仓库直接构建的当前文档位于入门指南。基本上有一些额外步骤来创建包含目录树以及运行构建本身。请注意,还要确保您使用克隆仓库中的b2命令,而不是您系统中可能预编译的任何内容。


谢谢@GrafikRobot,我跟着链接构建了最新版本的boost。 - user001
如何克隆特定的模块而不是所有模块? - Richard Dally
1
@LeFlou 别进行递归的 git 克隆。然后对于特定的模块,执行以下操作:git submodule update --init "libs/whatever" - GrafikRobot

17

要从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

其中 $1predef$2master$3libs,也就是运行 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存储库上进行测试):

-- 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

9

我确实错过了文档中的一些重要部分:.\b2 headers。以下是我为构建threadchronodate-time所做的所有工作,包括版本1.60.0,从GitHub代码库克隆(在Windows机器上),无论是发布版还是调试版,无论是静态库还是共享库:

git clone --recursive https://github.com/boostorg/boost.git
cd boost
git checkout boost-1.60.0
git submodule update
bootstrap.bat
.\b2.exe headers
.\b2.exe variant=release,debug link=static,shared address-model=32 architecture=x86 --with-thread --with-chrono --with-date_time --stagedir=stage\win32 stage
.\b2.exe variant=release,debug link=static,shared address-model=64 architecture=x86 --with-thread --with-chrono --with-date_time --stagedir=stage\x64 stage

别忘了:

.\b2.exe headers

0
我之前也遇到了同样的问题。最简单的解决方法就是缺少tools/build.git。https://github.com/boostorg/build.git。只需在目录中执行git submodule update --recursive --remote即可解决。这将下载丢失的tools/build和其他相关文件夹。
请注意,除了构建子模块之外,还会相应地下载更多的子模块。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接