怎么下载安装包,请参见如何从github上下载对应安装包。(其实就是从GitHub上spdlog 的仓库下载就好)
这里介绍怎样安装spdlog这个日志管理使用的库。
- 首先将源码包解压到自己的目录下。
[zry@localhost package]$ ls date-master git-2.34.1 ormpp-master Python-3.8.0 spdlog-1.x sqlpp11-main
- 进入到spdlog解压文件夹内
[zry@localhost package]$ cd spdlog-1.x/ [zry@localhost spdlog-1.x]$ ls appveyor.yml bench build cmake CMakeLists.txt example include INSTALL LICENSE logos README.md scripts src tests
- 创建build 目录,用来存放cmake编译 相关内容
[zry@localhost spdlog-1.x]$ mkdir build
- 进入到build目录内
[zry@localhost spdlog-1.x]$ cd build/
- 进行cmake 编译,命令
cmake ..
[zry@localhost build]$ cmake .. -- 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 -- Build spdlog: 1.12.0 -- 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 -- Build type: Release -- Generating example(s) -- Generating install -- Configuring done -- Generating done -- Build files have been written to: /home/zry/package/spdlog-1.x/build
- 进行编译 命令
make -j
[zry@localhost build]$ make -j [ 10%] Building CXX object CMakeFiles/spdlog.dir/src/spdlog.cpp.o [ 20%] Building CXX object CMakeFiles/spdlog.dir/src/stdout_sinks.cpp.o [ 30%] Building CXX object CMakeFiles/spdlog.dir/src/color_sinks.cpp.o [ 40%] Building CXX object CMakeFiles/spdlog.dir/src/file_sinks.cpp.o [ 50%] Building CXX object CMakeFiles/spdlog.dir/src/async.cpp.o [ 60%] Building CXX object CMakeFiles/spdlog.dir/src/cfg.cpp.o [ 70%] Building CXX object CMakeFiles/spdlog.dir/src/bundled_fmtlib_format.cpp.o [ 80%] Linking CXX static library libspdlog.a [ 80%] Built target spdlog [ 90%] Building CXX object example/CMakeFiles/example.dir/example.cpp.o [100%] Linking CXX executable example [100%] Built target example
- 编译完成之后可以进行测试 在 build 目录下会有一个
example
文件夹,进入后执行./example
可以看到测试结果。
[zry@localhost build]$ ls CMakeCache.txt cmake_install.cmake CPackSourceConfig.cmake libspdlog.a spdlogConfig.cmake spdlogConfigVersion.cmake CMakeFiles CPackConfig.cmake example Makefile spdlogConfigTargets.cmake spdlog.pc [zry@localhost build]$ cd example/ [zry@localhost example]$ ls CMakeFiles cmake_install.cmake example Makefile [zry@localhost example]$ ./example [2024-02-26 17:46:12.223] [info] Welcome to spdlog version 1.12.0 ! [2024-02-26 17:46:12.224] [warning] Easy padding in numbers like 00000012 [2024-02-26 17:46:12.224] [critical] Support for int: 42; hex: 2a; oct: 52; bin: 101010 [2024-02-26 17:46:12.224] [info] Support for floats 1.23 [2024-02-26 17:46:12.224] [info] Positional args are supported too.. [2024-02-26 17:46:12.224] [info] right aligned, left aligned [2024-02-26 17:46:12.224] [debug] This message should be displayed.. [17:46:12 +08:00] [I] [thread 16553] This an info message with custom format [2024-02-26 17:46:12.224] [info] ****************** Backtrace Start ****************** [2024-02-26 17:46:12.224] [debug] Backtrace message 90 [2024-02-26 17:46:12.224] [debug] Backtrace message 91 [2024-02-26 17:46:12.224] [debug] Backtrace message 92 [2024-02-26 17:46:12.224] [debug] Backtrace message 93 [2024-02-26 17:46:12.224] [debug] Backtrace message 94 [2024-02-26 17:46:12.224] [debug] Backtrace message 95 [2024-02-26 17:46:12.224] [debug] Backtrace message 96 [2024-02-26 17:46:12.224] [debug] Backtrace message 97 [2024-02-26 17:46:12.224] [debug] Backtrace message 98 [2024-02-26 17:46:12.224] [debug] Backtrace message 99 [2024-02-26 17:46:12.224] [info] ****************** Backtrace End ******************** [2024-02-26 17:46:12.226] [info] Binary example: 0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 0060: 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 0080: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f [2024-02-26 17:46:12.226] [info] Another binary example:00 00 00 00 00 00 00 00 00 00 [2024-02-26 17:46:12.226] [info] Vector example: [1, 2, 3] [multi_sink_example] [warning] this should appear in both console and file [2024-02-26 17:46:12.226] [info] user defined type: [my_type i=14] [2024-02-26 17:46:12.350] [info] Stopwatch: 0.123150527 seconds [2024-02-26 17:46:12.350] [info] Before opening logs/events-sample.txt [2024-02-26 17:46:12.350] [info] After opening logs/events-sample.txt [2024-02-26 17:46:12.350] [info] Before closing logs/events-sample.txt [2024-02-26 17:46:12.350] [info] After closing logs/events-sample.txt [2024-02-26 17:46:12.350] [info] End of example. [2024-02-26 17:46:12.350] [console] [info] End of example. [zry@localhost example]$ ll -lrt 总用量 580 -rw-rw-r--. 1 zry zry 8745 2月 26 17:44 Makefile -rw-rw-r--. 1 zry zry 1282 2月 26 17:44 cmake_install.cmake drwxrwxr-x. 3 zry zry 4096 2月 26 17:44 CMakeFiles -rwxrwxr-x. 1 zry zry 567664 2月 26 17:44 example drwxr-xr-x. 2 zry zry 4096 2月 26 17:46 logs [zry@localhost example]$
分享一个有趣的 学习链接:https://xxetb.xet.tech/s/HY8za