0

I have a library MyLib/0.1@myself/testing that is uploaded to remote: myconan-test I'm searching how to use it in a consumer with conanfile.py. The package is downloaded in cache after the installing step. But I have an error while compiling the consumer Cannot specify link libraries for target "MyLib" which is not built by this project. Could you explain the cause of my error? Thank you

My project

consumer_MyLib
|-conanfile.py
|-build
|-src
|    |-CMakeLists.txt
     |-example.cpp

My conanfile.py

from conans import ConanFile, CMake

class ConsumeMyLibConan(ConanFile):
   settings = "os", "compiler", "build_type", "arch"
   requires = "MyLib/0.1@myself/testing"
   generators = "cmake", "gcc", "txt"

   def build(self):
      cmake = CMake(self)
      cmake.configure(source_folder="src")
      cmake.build()

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12)
project(consumer_MyLib CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${project_name} example.cpp)
target_link_libraries(${project_name}  ${CONAN_LIBS})

Steps that I did to compile:

mkdir build & cd build
conan install ..
conan build ..

The output error

[user@dev build]$ conan build ..
      Using lockfile: '/home/user/Projects/consumer_MyLib/build/conan.lock'
Using cached profile from lockfile
conanfile.py: Running build()
-- Conan: called by CMake conan helper
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Conan: Checking correct version: 4.8
-- Conan: C++ stdlib: libstdc++
CMake Error at CMakeLists.txt:23 (target_link_libraries):
  Cannot specify link libraries for target "MyLib" which is not built by this
  project.


-- Configuring incomplete, errors occurred!
See also "/home/user/Projects/consumer_MyLib/build/CMakeFiles/CMakeOutput.log".
ERROR: conanfile.py: Error in build() method, line 15
        cmake.configure(source_folder="src")
        ConanException: Error 1 while executing cd '/home/user/Projects/consumer_MyLib/build' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release" -DCONAN_IN_LOCAL_CACHE="OFF" -DCONAN_COMPILER="gcc" -DCONAN_COMPILER_VERSION="4.8" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libstdc++" -DCMAKE_INSTALL_PREFIX="/home/user/Projects/consumer_MyLib/build/package" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -Wno-dev '/home/user/Projects/consumer_MyLib/src'



muocdich
  • 41
  • 1
  • 8
  • 2
    Name of the project is contained in [PROJECT_NAME](https://cmake.org/cmake/help/v3.9/variable/PROJECT_NAME.html) variable. The variable `project_name` which you use is **empty** (CMake doesn't set it), so the call `add_executable(${project_name} example.cpp)` is effectively the same as `add_executable(example.cpp)` (without the first argument!) and call `target_link_libraries(${project_name} ${CONAN_LIBS})` is effectively the same as `target_link_libraries(${CONAN_LIBS})` which leads you to the error. – Tsyvarev Apr 07 '20 at 10:43
  • It is very possible that the libstdc++ setting is not the correct one. Have you read the green "Important" notice in https://docs.conan.io/en/latest/getting_started.html? Or are you really using gcc 4.8? What is the profile that was used when you did ``conan install``? – drodri Apr 07 '20 at 11:24
  • 1
    Thank for your help. I can compile my project now. It was the variable PROJECT_NAME which cased the problem. – muocdich Apr 07 '20 at 12:26

0 Answers0