"boost bcp --namespace" 究竟是什么?

3
我认为使用boost bcp工具中的namespace选项可以重命名所列模块的包含和定义。然而,在运行该工具并检查输出后,似乎并没有实现这一点。如果它们仍然包含 #include <boost/*> 并且期望最终用户的 #include <boost/*> 不会导致版本冲突,那我该如何重新分发它们呢?它只是用命名空间包装这些吗?
我使用了以下bcp命令:
.\boost_1_53_0\dist\bin\bcp.exe --boost=boost_1_53_0 --namespace=myboost --namespace-alias smart_ptr filesystem array.hpp container move ptr_container algorithm/string.hpp tokenizer.hpp thread chrono atomic foreach.hpp build myboost

一个文件的快速grep结果如下:
[boost]grep -e "boost/" algorithm\string.hpp
grep -e "boost/" algorithm\string.hpp
#include <boost/algorithm/string/std_containers_traits.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/find.hpp>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/erase.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/find_iterator.hpp>

我非常确定这是使用带有命名空间选项的bcp工具的用例,但是,我显然误解了一些常见的C++概念/用法,对吧?或者,也许我在错误地使用该工具吗?
提前感谢任何见解。

1
此外,我的同事坚持认为我们必须在所有包含和定义中搜索和替换“boost”。然而,像这个帖子一样的文章表明,bcp已经做到了这一点!??? - kevinmm
1
只是想澄清一下,我确实理解该工具的主要重点是扫描boost模块的依赖项并将它们复制到输出路径。我主要关注--namespace和--namespace-alias选项,以及它们提供的其他功能。 - kevinmm
2个回答

3
regex config build /foo将完整的regex库(位于libs/regex)、config库(libs/config)和构建系统(tools/build),以及所有依赖项一起复制到/foo。还将boost命名空间更改为myboost,并将二进制库的文件名前缀从“boost”更改为“myboost”。--namespace-alias选项将命名空间boost设置为新名称的别名。只有二进制文件会被重命名(libboost_regex.so将变成libmyboost_regex.so),头文件不会。此外,命名空间boost将被替换为myboost(并且boost将是myboost的别名)。

1
那么...在BCP的#include语句中无法避免版本冲突,对吗?我也遇到了同样的问题。当然,命名空间已经更改,但是任何使用boost的其他代码都会在我的头文件副本存在时选择它们。 - flodin

0

如其名,它重命名了命名空间和库文件(即.dll和.lib),但不会重命名标头所在的目录,因此也不会重命名包含文件。

Boost库通常位于命名空间boost中。使用bcp,您将该命名空间更改为myboost。因此,例如,此代码成为有效:

#include <boost/sharedptr.hpp> //header directories haven't changed

myboost::shared_ptr<int> pi = myboost::make_shared<int>(5); //but the namespace has

感谢 --namespace-alias,您可以继续使用命名空间 boost,因为 boost 已成为 myboost 的别名:

boost::shared_ptr<int> pi; //ok, this is in fact a myboost::shared_ptr

请参阅文档中的示例:http://www.boost.org/doc/libs/1_53_0/tools/bcp/doc/html/index.html


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