muocdich
muocdich

Reputation: 41

conan C++ ERROR: Unable to find Package in remotes

I'm new to Conan. I tried to create a package and upload into remote (myconan-test). The package is in local cache and in remote.

Package in local

[user@dev build]$ conan search MyLib*
Existing package recipes:

MyLib/0.1@myself/Testing

Upload package to remote

[user@dev build]$ conan upload MyLib/0.1@myself/testing -r=myconan-test
Uploading to remote 'myconan-test':
Uploading MyLib/0.1@myself/testing to remote 'myconan-test'
Compressing conan_sources.tgz completed [3 files]
Uploading conanmanifest.txt completed [0.24k]
Uploaded conan recipe 'MyLib/0.1@myself/testing' to 'myconan-test': http://xxx.xx.xx.xx:8081/artifactory/api/conan/conan-local

Now package is in remote

[user@dev build]$ conan search MyLib* -r=myconan-test
Existing package recipes:

MyLib/0.1@myself/testing

I created a consumer project that uses MyLib/0.1. But when I did: conan install .. I had an error like:

MyLib/0.1: Not found in local cache, looking in remotes...
MyLib/0.1: Trying with 'conan-center'...
MyLib/0.1: Trying with 'myconan-test'...
ERROR: Unable to find 'MyLib/0.1' in remotes

My conanfile.txt is

[requires]
MyLib/0.1

[generators]
gcc
cmake
txt

[imports]
bin, *.a -> ./bin # Copies all dll files from the package "bin" folder to my project "bin" folder

If I change the require to: MyLib/0.1@myself/testing. It works because it uses the package in cache. My question is how I can use the remote package. What is my error?

Thank you in advance.

EDIT--- After understanding how to call my package by adding MyLib/0.1@myself/testing. I can download the package from remote. But in the building step, I have an 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.**

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})

Upvotes: 2

Views: 10574

Answers (2)

drodri
drodri

Reputation: 5962

You are missing the @user/channel part in your requires:

[requires]
MyLib/0.1@myself/testing

When you are uploading the packages, you probably want to add --all to make sure you upload the binary too:

conan upload MyLib/0.1@myself/testing -r=myconan-test --all

Check the upload command in the docs.

If you want to make sure that your cache doesn't have the package, do a conan remove "*" -f

Upvotes: 2

uilianries
uilianries

Reputation: 3887

The package reference in conanfile.txt is declared using its name, version, user and channel. Both user and channel are used as a namespace and they are important to the package reference. Besides that, Conan also supports package names without a namespace, thus we can have:

zlib/1.2.11
zlib/1.2.11@acme/stable
zlib/1.2.11@acme/testing

Here we have 3 packages, both are related to zlib/1.2.11, but they are different packages. The first doesn't have a namespace, however it's a valid package name and it's owned by Conan Center Index. The other 2 packages are provided by acme, but have different channels. Conan see each package reference as unique, so if you refer zlib/1.2.11 in your conanfile.txt it will look for the first package only.

Now backing to your situation, you created the package MyLib/0.1@myself/Testing, and Conan search command returned it when using the regex, which is plausible because is a search command. However, when referring the package in your conanfile.txt, you have to use the complete reference which follows your package:

# conanfile.txt

[requires]
MyLib/0.1@myself/Testing

...

If you look for MyLib/0.1 only, Conan will take it as a valid reference, and won't complete with your reference. There is no implicit deduction.

Upvotes: 3

Related Questions