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'