先编译 libfmt.a :
cd ~/3rd;
git clone https://github.com/fmtlib/fmt.git && cd fmt
rm _build -rf;
mkdir _build -p
cd _build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
make -j$(nproc)
make install
再编译 quill ,需要先下载源文件:
cd ~/3rd;
git clone https://github.com/odygrd/quill
cd quill
在编译之前,我喜欢将 LOG 的级别显示我更喜欢的。QUILL 默认 LOG 级别为 TRACE_L3, TRACE_L2, TRACE_L1, DEBUG, INFO, WARNING, ERROR, CRITICAL ,我喜欢 ALL, DETAIL, TRACE, DEBUG, INFO, WARNING, ERROR, FATAL。这需要修改 `quill/src/LogLevel.cpp 的 log_levels_map 变量:
std::string_view loglevel_to_string(LogLevel log_level)
{
static constexpr std::array<std::string_view, 11> log_levels_map = {
- {"TRACE_L3", "TRACE_L2", "TRACE_L1", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL",
+ {"ALL", "DETAIL", "TRACE", "DEBUG", "INFO", "WARNING", "ERROR", "FATAL",
"BACKTRACE", "NONE", "DYNAMIC"}};
继续编译:
rm _build -rf;
mkdir _build -p
cd _build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/ -DQUILL_FMT_EXTERNAL=ON -DCMAKE_PREFIX_PATH=/opt/lib/cmake/fmt/ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
make install
编译出的库文件是 /opt/lib/libquill.a。下面方法会编译动态链接库:/opt/lib/libquill.so。
rm _build -rf
mkdir _build -p
cd _build
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/ -DQUILL_FMT_EXTERNAL=ON -DCMAKE_PREFIX_PATH=/opt/lib/cmake/fmt/ -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE -DBUILD_SHARED_LIBS=ON
make install
如果使用动态链接库,需要在引入 Quill.h
之前定义或在编译参数里添加宏 QUILL_BUILD_SHARED
。
Q. E. D.