1

I'm setting up a c++ project, which uses cmake and has two build type:

  • debug, having a cmake-build-debug folder
  • release, having a cmake-build-release folder

I want to add plog through cmake, so I installed it successfully by defining a conanfile.txt:

[requires]
plog/1.1.5

[generators]
cmake

then, I conan install . on my root and I edited my CMakeLists.txt like this:

set(CMAKE_VERBOSE_MAKEFILE ON)
cmake_minimum_required(VERSION 3.17)
project(test)

set(CMAKE_CXX_STANDARD 20)
set(CXX_EXTENSIONS OFF)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
    set(LLVM_ENABLE_WARNINGS ON)
endif()

# ADDED ROW
include(conanbuildinfo.cmake)

add_executable(primo main.cpp io.cpp io.h)

# ADDED ROW
target_link_libraries(plog ${CONAN_LIBS})

the problem is that cmake complaints about the last row:

CMake Error at CMakeLists.txt:15 (target_link_libraries):
  Cannot specify link libraries for target "plog" which is not built by this
  project.

I'm new to cmake so maybe I've configured it badly. What seems to be the problem?

Bertuz
  • 2,390
  • 3
  • 25
  • 50
  • 2
    According to [here](https://docs.conan.io/en/latest/getting_started.html), you need to call `conan_basic_setup()` function after include `conanbuildinfo.cmake`. –  Dec 09 '20 at 00:28
  • 2
    The first argument to the `target_link_libraries` is **your** executable, which you want to link with the libraries (the rest arguments). Probably, you mean `target_link_libraries(primo plog ${CONAN_LIBS})`. – Tsyvarev Dec 09 '20 at 07:44
  • @adembudak is right. Or, you can use `cmake_find_package` generator, which is more transparent: https://docs.conan.io/en/latest/reference/generators/cmake_find_package.html – uilianries Dec 09 '20 at 10:53
  • @Tsyvarev bingo, that was it! – Bertuz Dec 09 '20 at 18:45
  • actually now I get a `[ 50%] Linking CXX executable bin/first ld: library not found for -lplog clang: error: linker command failed with exit code 1 (use -v to see invocation)` – Bertuz Dec 09 '20 at 18:53
  • 1
    I think that you need to remove `plog` from `target_link_libraries` and leave just `target_link_libraries(primo ${CONAN_LIBS})`. Plog should be available as part of conan libs – ymochurad Dec 09 '20 at 19:32

0 Answers0