0

I installed spdlog static lib using there doc and try to link it to my program using there example the installation path is this: /home/yaodav/Desktop/dnr_main_repo/lib/external

this is my CMAKE:

cmake_minimum_required(VERSION 3.19)
project(test_1)

set(CMAKE_CXX_STANDARD 17)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.75.0 COMPONENTS date_time system thread CONFIG)
if(Boost_FOUND)
    message("Boost found ${Boost_VERSION}")
    message("${Boost_LIBRARIES}")
endif()
find_library(CONNECTION
        NAMES connlib
        )
if(NOT CONNECTION)
    message(FATAL_ERROR "CONNECTION library not found")
else()
    message("CONNECTION library found")
endif()

if(NOT TARGET spdlog)
    # Stand-alone build
    find_package(spdlog REQUIRED)
endif()


find_package(Threads)

add_executable(test_1 main.cpp)
target_link_libraries(test_1 PRIVATE ${CONNECTION} ${Boost_LIBRARIES} Threads::Threads pq spdlog::spdlog)

but Im getting this error:

CMake Error at CMakeLists.txt:23 (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

Add the installation prefix of "spdlog" to CMAKE_PREFIX_PATH or set "spdlog_DIR" to a directory containing one of the above files. If "spdlog" provides a separate development package or SDK, be sure it has been installed.

so I added the spdlog_DIR set(spdlog_DIR ../lib/external/spdlog find_package(spdlog PATHS ${spdlog_DIR } REQUIRED) with this error:

include could not find load file:

    /home/yaodav/Desktop/dnr_main_repo/lib/external/spdlog/build/spdlogConfigTargets.cmake
Sahith Vibudhi
  • 4,935
  • 2
  • 32
  • 34
yaodav
  • 1,126
  • 12
  • 34
  • Does `/home/yaodav/Desktop/dnr_main_repo/lib/external/spdlog/build/spdlogConfigTargets.cmake` exist? – Stephen Newell Aug 25 '21 at 17:18
  • @StephenNewell no, it farther down `/home/yaodav/Desktop/dnr_main_repo/lib/external/spdlog/build/CMakeFiles/Export/lib64/cmake/spdlog/spdlogConfigTargets.cmake` but when Im changing the spdlog_DIR to ther it telling me that i need the path to `spdlogConfig.cmake` – yaodav Aug 25 '21 at 17:23
  • 1
    "I installed spdlog static lib using there doc" - Funny, but [Install section](https://github.com/gabime/spdlog#install) does NOT **install** `spdlog`, it just **builds** it. For **installing** you need to additionally run `make install`. Make sure that you choose appropriate install prefix (`CMAKE_INSTALL_PREFIX` when running `cmake`). – Tsyvarev Aug 25 '21 at 17:25
  • @Tsyvarev do i have to install it if i want to use it? – yaodav Aug 25 '21 at 17:27
  • In their [CMakeLists.txt](https://github.com/gabime/spdlog/blob/v1.x/CMakeLists.txt) I see no `export()` call, so without installing the package you cannot use `find_package` for locate it. Note, that "installing" doesn't mean "installing into the system directory". As I said above, by using `CMAKE_INSTALL_PREFIX` you could choose the directory where the package will be installed. – Tsyvarev Aug 25 '21 at 17:29
  • @Tsyvarev like this `make install --prefix=CMAKE_INSTALL_PREFIX` ? – yaodav Aug 25 '21 at 17:34
  • No, it is like `cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/dir ..` + `make install`. See e.g. [that question](https://stackoverflow.com/questions/6003374/what-is-cmake-equivalent-of-configure-prefix-dir-make-all-install) about setting installation directory in CMake. – Tsyvarev Aug 25 '21 at 17:37
  • Did you try using `ExternalProject` or `FetchContent`, too? Here's the description: https://github.com/gabime/spdlog/wiki/9.-CMake#use-as-static-library-with-externalproject_add-as-git-submodule I use ```FetchContent_Declare( spdlog GIT_REPOSITORY https://github.com/gabime/spdlog.git GIT_TAG v1.9.2 ) FetchContent_MakeAvailable(spdlog)``` and you may add the options from the wiki back in if you like. – RL-S Nov 17 '21 at 14:29
  • The advantage of `ExternalProject` or `FetchContent` is, that you don't need a separate install step. – RL-S Nov 17 '21 at 14:37

2 Answers2

2

I found using FetchContent with spdlog was also the easiest. Just added these lines to my project:

...
Include(FetchContent)
FetchContent_Declare(
    spdlog
    GIT_REPOSITORY https://github.com/gabime/spdlog.git
    GIT_TAG v1.9.2
)
FetchContent_MakeAvailable(spdlog)
add_executable(project main.cpp)
target_link_libraries(project PRIVATE spdlog::spdlog)
...
Petri
  • 81
  • 1
  • 5
0

Install libspdlog-dev. No need to change CMake files. Similar problem here.