CentOS 7 使用Fmt库

安装

fmt Git下载地址:https://github.com/fmtlib/fmt

步骤1:首先,你需要下载fmt的源代码。你可以从https://github.com/fmtlib/fmt或者源代码官方网站下载。并上传至/usr/local/source_code/

步骤2:下载完成后,需要将源代码解压,可以使用以下命令:

复制代码
 tar -zxvf fmt-10.0.0.tar.gz

步骤3:解压后,切换到源代码目录:

复制代码
[root@localhost source_code]# cd fmt-10.0.0

步骤4:生成fmt 动态/静态库,执行如下指令:

复制代码
mkdir build
cd build
cmake ..
make && make install

[root@localhost fmt-10.0.0]# mkdir build
[root@localhost fmt-10.0.0]# cd build/
[root@localhost build]# cmake ..
-- CMake version: 3.21.2
-- The CXX compiler identification is GNU 8.3.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /opt/rh/devtoolset-8/root/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Version: 10.0.0
******
[root@localhost build]# make && make install
[  1%] Building CXX object CMakeFiles/fmt.dir/src/format.cc.o
[  2%] Building CXX object CMakeFiles/fmt.dir/src/os.cc.o
[  4%] Linking CXX static library libfmt.a
[  4%] Built target fmt
******
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib64/libfmt.a
-- Installing: /usr/local/include/fmt/args.h
-- Installing: /usr/local/include/fmt/chrono.h
-- Installing: /usr/local/include/fmt/color.h
-- Installing: /usr/local/include/fmt/compile.h
-- Installing: /usr/local/include/fmt/core.h
-- Installing: /usr/local/include/fmt/format.h
-- Installing: /usr/local/include/fmt/format-inl.h
-- Installing: /usr/local/include/fmt/os.h
-- Installing: /usr/local/include/fmt/ostream.h
-- Installing: /usr/local/include/fmt/printf.h
-- Installing: /usr/local/include/fmt/ranges.h
-- Installing: /usr/local/include/fmt/std.h
-- Installing: /usr/local/include/fmt/xchar.h
-- Installing: /usr/local/lib64/cmake/fmt/fmt-config.cmake
-- Installing: /usr/local/lib64/cmake/fmt/fmt-config-version.cmake
-- Installing: /usr/local/lib64/cmake/fmt/fmt-targets.cmake
-- Installing: /usr/local/lib64/cmake/fmt/fmt-targets-release.cmake
-- Installing: /usr/local/lib64/pkgconfig/fmt.pc

温馨提示:完成以上步骤后,在/usr/local/lib64下会生成libfmt.so动态库和/usr/local/include下生成fmt文件夹。你可以使用以下命令查看是否安装成功:

复制代码
ls /usr/local/lib64 | grep fmt
ls /usr/local/include | grep fmt

如果看到,则说明成功安装了fmt库 .

快速入门

在/usr/local/source_code 新增fmt_demo 目录并新增test_fmt.cpp 文件,文件内容如下:

复制代码
#include "fmt/core.h"

int main(){
        fmt::print("Hello,{}", "Fmt");
        return 0;
}

编译源码并执行:

复制代码
[root@localhost source_code]# vi test_fmt.cpp
[root@localhost source_code]# g++ test_fmt.cpp -o test_fmt  -lfmt
[root@localhost source_code]# ./test_fmt
Hello,Fmt

入门指南

参考资料:fmt Git地址

fmt 官方文档

fmt 快速入门文档

相关推荐
zhaotiannuo_19981 小时前
渗透测试之docker
运维·docker·容器
王正南2 小时前
kali-linux 虚拟机连接安卓模拟器
android·linux·运维·虚拟机连接模拟器·安卓模拟器,linux虚拟机
三不原则2 小时前
故障案例:容器启动失败排查(AI运维场景)——从日志分析到根因定位
运维·人工智能·kubernetes
吳所畏惧2 小时前
Linux环境/麒麟V10SP3下离线安装Redis、修改默认密码并设置Redis开机自启动
linux·运维·服务器·redis·中间件·架构·ssh
yueguangni2 小时前
sysstat 版本 10.1.5 是 CentOS 7 的默认版本,默认情况下确实不显示 %wait 字段。需要升级到新版sysstat
linux·运维·centos
funfan05173 小时前
【运维】MySQL数据库全量备份与恢复实战指南:从入门到精通
运维·数据库·mysql
-dcr3 小时前
49.python自动化
运维·python·自动化
萧曵 丶4 小时前
Linux 业务场景常用命令详解
linux·运维·服务器
豆是浪个4 小时前
Linux(Centos 7.6)命令详解:ps
linux·windows·centos
乾元5 小时前
ISP 级别的异常洪泛检测与防护——大流量事件的 AI 自动识别与响应工程
运维·网络·人工智能·安全·web安全·架构