我正在尝试在项目中使用spdlog。根据spdlog docu,我只需要复制include文件夹下的文件并使用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)
但以上方法均无效。有谁知道我该如何解决?非常感谢!
最佳答案
如spdlogs docu at the very bottom所述,您可以
find_package(spdlog CONFIG)
这为您提供了导入的接口库
spdlog::spdlog
,您可以使用它target_link_library(my_library PUBLIC spdlog::spdlog)
(如spdlog/examples/CMakeLists.txt中所示)