c++ - 为什么 fmt 库不是仅标头?
解决方案
正如其他人已经正确指出的那样,主要原因是构建速度。例如,使用静态库(默认)编译比仅使用标头库快约 2.75 倍:
#include <fmt/core.h>
int main() {
fmt::print("The answer is {}.", 42);
}
% time c++ -c test.cc -I include -std=c++11
c++ -c test.cc -I include -std=c++11 0.27s user 0.05s system 97% cpu 0.324 total
% time c++ -c test.cc -I include -std=c++11 -DFMT_HEADER_ONLY
c++ -c test.cc -I include -std=c++11 -DFMT_HEADER_ONLY 0.81s user 0.07s system 98% cpu 0.891 total
在仅标头库中,实现细节和依赖关系泄漏到使用它们的每个翻译单元中。
推荐阅读
- powershell - 拆分输入并并行运行 awk 命令
- c# - 使用 IViewComponentHelper 将 ViewComponent 转换为 HTML 字符串时的线程问题
- excel - VBA 在特定日期格式 dd/mm/yyyy h:mm:ss 之间过滤数据
- c - GetConsoleCursorInfo 在 Windows 7 SP1 上崩溃
- javascript - 将 https.get 的返回对象设置为变量
- reactjs - 测试失败
- reactjs - 反应为子组件添加两个父母
- azure-policy - 你如何在 Azure 中强制执行整数个标记值
- html - 页脚卡在 HTML 中间
- c# - 加载图像时 Windows Media Player 崩溃 Windows 10