Conan: starting at a text book Hello World

Command Lines

  1. to search libraries from conancenter
    # conan search poco --remote=conancenter
  2. to inspect the metadata of a library
    # conan inspect poco/1.9.4
  3. to install the library and the dependency but also the transitive dependencies, and generate the information for the build system(be sure there is a recipe in current directory)
    # conan install
  4. to search for packages in the local cache
    # conan search “ ∗ *
E:\workplace\Conan\Repository\examples\libraries\poco\md5>conan search "*"
Existing package recipes:

bzip2/1.0.8
expat/2.5.0
openssl/1.1.1t
pcre/8.45
poco/1.9.4
sqlite3/3.40.1
zlib/1.2.13

  1. to inspect the different binary packages of a reference. The @ symbol at the end of the package name is important to search for a specific package. If you don’t add the @, Conan will interpret the argument as a pattern search and return all the packages that match the poco/1.9.4 pattern and may have different user and channel.
    # conan search poco/1.9.4@
E:\workplace\Conan\Repository\examples\libraries\poco\md5>conan search poco/1.9.4@
Existing packages for recipe poco/1.9.4:

    Package_ID: 827d0093fffd24b2cf1576c6515a7f7707d5d2b9
        [options]
            enable_apacheconnector: False
            enable_cppparser: False
            enable_crypto: True
            enable_data: True
            enable_data_odbc: False
            enable_data_sqlite: True
            enable_encodings: True
            enable_json: True
            enable_mongodb: True
            enable_net: True
            enable_netssl: True
            enable_netssl_win: False
            enable_pagecompiler: False
            enable_pagecompiler_file2page: False
            enable_pdf: False
            enable_pocodoc: False
            enable_redis: True
            enable_sevenzip: False
            enable_util: True
            enable_xml: True
            enable_zip: True
            shared: False
        [settings]
            arch: x86_64
            build_type: Release
            compiler: Visual Studio
            compiler.runtime: MD
            compiler.version: 16
            os: Windows
        [requires]
            bzip2/1.0.8:d16a91eadaaf5829b928b12d2f836ff7680d3df5
            expat/2.5.0:ce5788ba7e3bb7dc834e36b06df66c481f42c99a
            openssl/1.1.1t:3fb49604f9c2f729b85ba3115852006824e72cab
            pcre/8.45:e87a8a0d1a34c63e57cfcfa8aa6088b17582df41
            sqlite3/3.40.1:1cb7125758648b3fd39bd045f772ec43fd26f71a
            zlib/1.2.13:3fb49604f9c2f729b85ba3115852006824e72cab
        Outdated from recipe: False

  1. to inspect all your current project’s dependencies use the conan info command by pointing it to the location of the conanfile.txt folder
    # conan info . . .. ..
    to generate a graph of your dependencies using Dot or HTML formats:
    # conan info . . .. .. --graph=file.html
E:\workplace\Conan\Repository\examples\libraries\poco\md5\build>conan info ..
WARN: pcre/8.45: requirement zlib/[>=1.2.11 <2] overridden by poco/1.9.4 to zlib/1.2.13
conanfile.txt
    ID: 4f96d5e60086be3b241f3740593e45556da2a223
    BuildID: None
    Context: host
    Requires:
        poco/1.9.4
bzip2/1.0.8
    ID: d16a91eadaaf5829b928b12d2f836ff7680d3df5
    BuildID: None
    Context: host
    ...
    ...
    

Configurations

  1. How to change the directory of Conan native repository or local cache?
    For Windows, open the configuration file C:\Users\Administrator.conan\conan.conf and modify the storage field:
    [storage]
    path = your_path

  2. ~/.conan/profiles/default, the file default is the configuration file detected by Conan, and this configuration is known as the default profile. A profile needs to be available prior to running commands such as conan install. When running the command, your settings are automatically detected (compiler, architecture. . . ) and stored as the default profile. You can edit these settings ~/.conan/profiles/default or create new profiles with your desired configuration.

point some self configurations:

# conan install .. --profile=gcc_x86
# conan install .. --settings arch=x86

default

[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
build_type=Release
[options]
[build_requires]
[env]


Preparation

Download the project of the example:
# git clone https://github.com/conan-io/examples.git

50105@DESKTOP-2PP2ND2 MINGW64 /e/workplace/Conan/Repository/examples/libraries/poco/md5 (master)
$ ls
CMakeLists.txt  README.md  build/  build.bat  build.sh*  conanfile.txt  md5.cpp
  1. md5.cpp, the source codes
#include "Poco/MD5Engine.h"
#include "Poco/DigestStream.h"

#include <iostream>


int main(int argc, char** argv)
{
    Poco::MD5Engine md5;
    Poco::DigestOutputStream ds(md5);
    ds << "abcdefghijklmnopqrstuvwxyz";
    ds.close();
    std::cout << Poco::DigestEngine::digestToHex(md5.digest()) << std::endl;
    return 0;
}

  1. From the source codes of md5.cpp, one can see that this application relies on the Poco libraries, which can be installed from ConanCenter remote:
# conan search poco --remote=conancenter
Existing package recipes:

poco/1.8.1
poco/1.9.3
poco/1.9.4
...
poco/1.13.0
# conan inspect poco/1.9.4
name: poco
version: 1.9.4
url: https://github.com/conan-io/conan-center-index
homepage: https://pocoproject.org
license: BSL-1.0
author: None
description: Modern, powerful open source C++ class libraries for building network- and internet-based applications that run on desktop, server, mobile and embedded systems.
...
...
  1. And the poco/1.9.4 is the interested version. The metadata of the 1.9.4 version are showed above.
  2. conanfile.txt, the crucial recipe that determines the package. In this example CMake is used to build the project, which is why the cmake generator is specified.
[requires]
poco/1.9.4

[generators]
cmake

  1. install the required dependencies and generate the information for the build system:
# mkdir build && cd build
# conan install ..
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=16
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

pcre/8.45: Not found in local cache, looking in remotes...
pcre/8.45: Trying with 'conancenter'...
Downloading conanmanifest.txt
Downloading conanfile.py
Downloading conan_export.tgz
pcre/8.45: Downloaded recipe revision 0
bzip2/1.0.8: Not found in local cache, looking in remotes...
...
...
poco/1.9.4: Package installed 827d0093fffd24b2cf1576c6515a7f7707d5d2b9
poco/1.9.4: Downloaded package revision 0
conanfile.txt: Generator cmake created conanbuildinfo.cmake
conanfile.txt: Generator txt created conanbuildinfo.txt
conanfile.txt: Aggregating env generators
conanfile.txt: Generated conaninfo.txt
conanfile.txt: Generated graphinfo

  1. cmake, the generator. To inject the Conan information, include the generated conanbuildinfo.cmake

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.12)
project(MD5Encrypter)

if(CMAKE_VERSION VERSION_LESS 3.0.0)
    include(CheckCXXCompilerFlag)
    check_cxx_compiler_flag(-std=c++11 COMPILER_SUPPORTS_CXX11)
    check_cxx_compiler_flag(-std=c++0x COMPILER_SUPPORTS_CXX0X)
    if(COMPILER_SUPPORTS_CXX11)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    elseif(COMPILER_SUPPORTS_CXX0X)
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
    endif()
else()
    SET(CMAKE_CXX_STANDARD 11)
    SET(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

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

add_executable(md5 md5.cpp)
target_link_libraries(md5 ${CONAN_LIBS})

  1. build and run MD5 app, in windows system case
> cmake .. -G "Visual Studio 16"
> cmake --build . --config Release

E:\workplace\Conan\Repository\examples\libraries\poco\md5\build\bin>md5.exe
c3fcd3d76192e4007dfb496cca67e13b
Press any key to continue. . .

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值