0

我正在尝试在我的项目中使用 spdlog。根据 spdlog docu,我只需要复制包含文件夹下的文件并使用 C++ 11 编译器。

我将 /include/spdlog 文件夹复制到我的项目根文件夹,但在尝试构建项目后出现了很多错误。有些是ff:

/home/project/Documents/project-server/spdlog/spdlog.h:46:39: error: variable or field ‘set_error_handler’ declared void
void set_error_handler(log_err_handler);
                                   ^
/home/project/Documents/project-server/spdlog/spdlog.h:46:24: error: ‘log_err_handler’ was not declared in this scope
 void set_error_handler(log_err_handler);
                    ^
In file included from /home/project/Documents/project-server/main.cpp:13:0:
/home/project/Documents/project-server/spdlog/spdlog.h:74:79: error: ‘filename_t’ does not name a type
 std::shared_ptr<logger> basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool truncate = false);
                                                                           ^
/home/project/Documents/project-server/spdlog/spdlog.h:75:79: error: ‘filename_t’ does not name a type
 std::shared_ptr<logger> basic_logger_st(const std::string& logger_name, const filename_t& filename, bool truncate = false);
                                                                           ^
/home/project/Documents/project-server/spdlog/spdlog.h:80:82: error: ‘filename_t’ does not name a type
 std::shared_ptr<logger> rotating_logger_mt(const std::string& logger_name, const filename_t& filename, size_t max_file_size, size_t max_files);

我尝试在 CMakeLists.txt 中添加以下内容

target_include_directories(ProjectName INTERFACE spdlog)

include_directories(spdlog)

target_link_libraries(ProjectName .... -libspdlog-dev)

(我安装了 libspdlog-dev)

add_subdirectory(spdlog)

但以上都不起作用。有谁知道我该如何解决这个问题?非常感谢!

4

2 回答 2

1

如最底部的spdlogs 文档中所写,您可以执行

find_package(spdlog CONFIG)

这为您提供了导入的接口库spdlog::spdlog,您可以使用它。

target_link_library(my_library PUBLIC spdlog::spdlog)

(如spdlog/examples/CMakeLists.txt中所示)

于 2017-07-26T09:24:14.623 回答
0

解决方案是安装 spdlog:

sudo apt-get install libspdlog-dev

并包括使用:

#include <spglog/spdlog.h>

我最初只是将 spdlog 复制到我的项目根目录并尝试使用:

#include "spdlog/spdlog.h"
于 2017-07-27T02:40:42.087 回答