1

I am new to c++, please don't grill too much. I am trying to use spdlog in C++ program and using CLion from Jetbrains.

Here is my screenshot but don't know what I am doing wrong. Please advise what I am doing wrong .

This is my main.cpp

#include <iostream>
#include "include/spdlog/spdlog.h"


int main() {
    std::cout << "Hello, World!" << std::endl;
    spdlog::info("hello world");
    return 0;
}

This my CMakeList.txt

cmake_minimum_required(VERSION 3.17) project(Lesson01)

set(CMAKE_CXX_STANDARD 14)

add_executable(Lesson01 main.cpp) include_directories(spdlog)

enter image description here

Thanks

Shax
  • 4,207
  • 10
  • 46
  • 62
  • 2
    Please post code as text not as image – Thomas Sablik Aug 21 '20 at 12:24
  • The error is pretty clear. you did not setup the include path correctly. For CLion you can do this in your CMakeLists.txt probably with the standard find_package() ... that you do for any third party library. – drescherjm Aug 21 '20 at 12:34
  • 1
    There is an example script for speedlog here: [https://github.com/twanas/spdlog-cmake/blob/master/CMakeLists.txt](https://github.com/twanas/spdlog-cmake/blob/master/CMakeLists.txt) your CMakeLists.txt missed the `find_package(spdlog)` and `target_link_libraries(lesson1 spdlog)` – drescherjm Aug 21 '20 at 12:37
  • @drescherjm, I tried your approach this is how my CMakeLists.txt looks like cmake_minimum_required(VERSION 3.17) project(Lesson01) set(CMAKE_CXX_STANDARD 14) find_package(spdlog) add_executable(Lesson01 main.cpp) target_link_libraries(lesson1 spdlog) – Shax Aug 21 '20 at 12:51
  • @drescherjm, now getting this error CMake Warning at CMakeLists.txt:7 (find_package): By not providing "Findspdlog.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "spdlog", but CMake did not find one. Could not find a package configuration file provided by "spdlog" with any of the following names: spdlogConfig.cmake spdlog-config.cmake – Shax Aug 21 '20 at 12:51
  • Do you have either of these files where you installed spdlog? From this I think the `spdlogConfig.cmake` should be created: [https://github.com/gabime/spdlog/tree/v1.x/cmake](https://github.com/gabime/spdlog/tree/v1.x/cmake) – drescherjm Aug 21 '20 at 12:55
  • You could install and configure spdlog using [Conan](https://conan.io/). Conan will set the include paths, library paths and libraries for you. It's a package and dependency manager for C++. – Thomas Sablik Aug 21 '20 at 13:05

2 Answers2

1

In the prototype you have created you have mentioned twice the keyword include First after the # and a second one in between the quotation mark.

I have been looking in internet and basic writting of spdlog prototype is just. Here the link: https://github.com/gabime/spdlog

#include "spdlog/spdlog.h"

Test is without the second include in your code.

All the best

Mathieu

  • Dear Mathieu, I tried your suggest but getting this error "spdlog/spdlog.h" file is not found. – Shax Aug 21 '20 at 12:46
0

In your code you have #include "include/spdlog/spdlog.h", and going by the screenshot you linked, this include is found. However it is then complaining that spdlog.h tries to #include <spdlog/common.h>, and this file is not found.

Together this sounds like you are not setting the right include directory for the library, and just getting the first file right by over-specifying the path.

I would try to change include_directories(spdlog) to include_directories(include) (or possibly include_directories(include/spdlog), not entirely sure which folder is the base one with the library in). If you want, then you can also add all of those; I don't think anything will break from adding too many here, but it may impact compile speed so try to only keep the correct one.

Also, after making this change you may need to change your original include from #include "include/spdlog/spdlog.h" to #include "spdlog/spdlog.h".

Frodyne
  • 3,547
  • 6
  • 16