0

I'm trying to use spdlog in my project. According to spdlog docu, I just need to copy files under include folder and use a C++ 11 compiler.

I copied the /include/spdlog folder to my project root folder but I'm having a lot of errors after trying to build the project. Some are the 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);

I have tried adding the following in the CMakeLists.txt

target_include_directories(ProjectName INTERFACE spdlog)

include_directories(spdlog)

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

(I installed libspdlog-dev)

add_subdirectory(spdlog)

but none of the above works. Does anyone know how I can fix this? Thanks a lot!

sabanana
  • 43
  • 6

2 Answers2

1

As written in spdlogs docu at the very bottom, you can do a

find_package(spdlog CONFIG)

This provides you the imported interface library spdlog::spdlog, which you can use

target_link_library(my_library PUBLIC spdlog::spdlog)

(as seen in the spdlog/examples/CMakeLists.txt)

Torbjörn
  • 5,512
  • 7
  • 46
  • 73
0

Solution was to install spdlog:

sudo apt-get install libspdlog-dev

and include using:

#include <spglog/spdlog.h>

I initially just copied spdlog to my project root and was trying to include using:

#include "spdlog/spdlog.h"
sabanana
  • 43
  • 6