Linux下编译fmt库

56 篇文章 3 订阅

下载

fmt的下载地址为https://github.com/fmtlib/fmt/tags,以下载版本8.1.1为例,下载后文件为fmt-8.1.1.tar.gz

编译

使用命令tar -zxvf fmt-8.1.1.tar.gz进行解压,解压完成后文件夹fmt-8.1.1中目录结构如下:

.
├── ChangeLog.rst
├── CMakeLists.txt
├── CONTRIBUTING.md
├── doc
├── include
├── LICENSE.rst
├── README.rst
├── src
├── support
└── test

使用命令mkdir build创建构建目录,然后进入build中(cd build),使用命令cmake ..构建工程,

[root@instance-1apocjsh build]# cmake ..
-- CMake version: 3.22.1
-- The CXX compiler identification is GNU 4.8.5
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Module support is disabled.
-- Version: 8.1.1
-- Build type: Release
-- CXX_STANDARD: 11
-- Performing Test has_std_11_flag
-- Performing Test has_std_11_flag - Success
-- Performing Test has_std_0x_flag
-- Performing Test has_std_0x_flag - Success
-- Performing Test SUPPORTS_USER_DEFINED_LITERALS
-- Performing Test SUPPORTS_USER_DEFINED_LITERALS - Success
-- Performing Test FMT_HAS_VARIANT
-- Performing Test FMT_HAS_VARIANT - Failed
-- Required features: cxx_variadic_templates
-- Looking for strtod_l
-- Looking for strtod_l - found
-- Target 'doc' disabled (requires doxygen)
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Performing Test HAVE_FNO_DELETE_NULL_POINTER_CHECKS
-- Performing Test HAVE_FNO_DELETE_NULL_POINTER_CHECKS - Success
-- FMT_PEDANTIC: OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /root/fmt-8.1.1/build

再使用命令make -j16进行编译,

[root@instance-1apocjsh build]# make -j16
[  4%] Built target fmt
[  7%] Built target gtest
Consolidate compiler generated dependencies of target test-main
[ 13%] Built target test-main
Consolidate compiler generated dependencies of target args-test
[ 16%] Built target args-test
[ 18%] Building CXX object test/CMakeFiles/assert-test.dir/assert-test.cc.o
[ 20%] Linking CXX executable ../bin/assert-test
[ 20%] Built target assert-test
[ 21%] Building CXX object test/CMakeFiles/chrono-test.dir/chrono-test.cc.o
[ 23%] Linking CXX executable ../bin/chrono-test
[ 23%] Built target chrono-test
[ 24%] Building CXX object test/CMakeFiles/color-test.dir/color-test.cc.o
[ 26%] Linking CXX executable ../bin/color-test
[ 26%] Built target color-test
[ 27%] Building CXX object test/CMakeFiles/core-test.dir/core-test.cc.o
[ 29%] Linking CXX executable ../bin/core-test
[ 29%] Built target core-test
[ 30%] Building CXX object test/CMakeFiles/gtest-extra-test.dir/gtest-extra-test.cc.o
[ 32%] Linking CXX executable ../bin/gtest-extra-test
[ 32%] Built target gtest-extra-test
[ 33%] Building CXX object test/CMakeFiles/format-test.dir/format-test.cc.o
[ 35%] Linking CXX executable ../bin/format-test
[ 35%] Built target format-test
Consolidate compiler generated dependencies of target format-impl-test
[ 36%] Building CXX object test/CMakeFiles/format-impl-test.dir/format-impl-test.cc.o
[ 38%] Building CXX object test/CMakeFiles/format-impl-test.dir/gtest-extra.cc.o
[ 40%] Linking CXX executable ../bin/format-impl-test
[ 46%] Built target format-impl-test
[ 47%] Building CXX object test/CMakeFiles/ostream-test.dir/ostream-test.cc.o
[ 49%] Linking CXX executable ../bin/ostream-test
[ 49%] Built target ostream-test
[ 50%] Building CXX object test/CMakeFiles/compile-test.dir/compile-test.cc.o
[ 52%] Linking CXX executable ../bin/compile-test
[ 52%] Built target compile-test
Consolidate compiler generated dependencies of target compile-fp-test
[ 53%] Building CXX object test/CMakeFiles/compile-fp-test.dir/compile-fp-test.cc.o
[ 55%] Building CXX object test/CMakeFiles/compile-fp-test.dir/gtest-extra.cc.o
[ 56%] Linking CXX executable ../bin/compile-fp-test
[ 61%] Built target compile-fp-test
[ 63%] Building CXX object test/CMakeFiles/printf-test.dir/printf-test.cc.o
[ 64%] Linking CXX executable ../bin/printf-test
[ 64%] Built target printf-test
[ 66%] Building CXX object test/CMakeFiles/ranges-test.dir/ranges-test.cc.o
[ 67%] Building CXX object test/CMakeFiles/ranges-test.dir/ranges-odr-test.cc.o
[ 69%] Linking CXX executable ../bin/ranges-test
[ 69%] Built target ranges-test
[ 70%] Building CXX object test/CMakeFiles/scan-test.dir/scan-test.cc.o
[ 72%] Linking CXX executable ../bin/scan-test
[ 72%] Built target scan-test
Consolidate compiler generated dependencies of target unicode-test
[ 73%] Building CXX object test/CMakeFiles/unicode-test.dir/unicode-test.cc.o
[ 75%] Linking CXX executable ../bin/unicode-test
[ 81%] Built target unicode-test
[ 83%] Building CXX object test/CMakeFiles/xchar-test.dir/xchar-test.cc.o
[ 84%] Linking CXX executable ../bin/xchar-test
[ 84%] Built target xchar-test
[ 86%] Building CXX object test/CMakeFiles/enforce-checks-test.dir/enforce-checks-test.cc.o
[ 87%] Linking CXX executable ../bin/enforce-checks-test
[ 87%] Built target enforce-checks-test
Consolidate compiler generated dependencies of target posix-mock-test
[ 89%] Building CXX object test/CMakeFiles/posix-mock-test.dir/posix-mock-test.cc.o
[ 90%] Building CXX object test/CMakeFiles/posix-mock-test.dir/gtest-extra.cc.o
[ 92%] Building CXX object test/CMakeFiles/posix-mock-test.dir/util.cc.o
[ 93%] Linking CXX executable ../bin/posix-mock-test
[ 96%] Built target posix-mock-test
[ 98%] Building CXX object test/CMakeFiles/os-test.dir/os-test.cc.o
[100%] Linking CXX executable ../bin/os-test
[100%] Built target os-test

最后使用命令make install DESTDIR=目标目录进行安装。

[root@instance-1apocjsh build]# make install DESTDIR=xxx
Install the project...
-- Install configuration: "Release"
-- Installing: xxx/usr/local/lib64/libfmt.a
-- Installing: xxx/usr/local/lib64/cmake/fmt/fmt-config.cmake
-- Installing: xxx/usr/local/lib64/cmake/fmt/fmt-config-version.cmake
-- Installing: xxx/usr/local/lib64/cmake/fmt/fmt-targets.cmake
-- Installing: xxx/usr/local/lib64/cmake/fmt/fmt-targets-release.cmake
-- Installing: xxx/usr/local/include/fmt/args.h
-- Installing: xxx/usr/local/include/fmt/chrono.h
-- Installing: xxx/usr/local/include/fmt/color.h
-- Installing: xxx/usr/local/include/fmt/compile.h
-- Installing: xxx/usr/local/include/fmt/core.h
-- Installing: xxx/usr/local/include/fmt/format.h
-- Installing: xxx/usr/local/include/fmt/format-inl.h
-- Installing: xxx/usr/local/include/fmt/locale.h
-- Installing: xxx/usr/local/include/fmt/os.h
-- Installing: xxx/usr/local/include/fmt/ostream.h
-- Installing: xxx/usr/local/include/fmt/printf.h
-- Installing: xxx/usr/local/include/fmt/ranges.h
-- Installing: xxx/usr/local/include/fmt/xchar.h
-- Installing: xxx/usr/local/lib64/pkgconfig/fmt.pc

安装完成后,将目标目录中的include目录lib64目录放入到新建的fmt目录,最终供外部使用的fmt目录结构如下:

[root@instance-1apocjsh fmt]# tree
.
├── include
│   └── fmt
│       ├── args.h
│       ├── chrono.h
│       ├── color.h
│       ├── compile.h
│       ├── core.h
│       ├── format.h
│       ├── format-inl.h
│       ├── locale.h
│       ├── os.h
│       ├── ostream.h
│       ├── printf.h
│       ├── ranges.h
│       └── xchar.h
└── lib64
    ├── cmake
    │   └── fmt
    │       ├── fmt-config.cmake
    │       ├── fmt-config-version.cmake
    │       ├── fmt-targets.cmake
    │       └── fmt-targets-release.cmake
    ├── libfmt.a
    └── pkgconfig
        └── fmt.pc

6 directories, 19 files

使用

直接查看其Readme.md,非常详细。

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值