本文档译自:https://docs.conan.io/en/latest/getting_started.html
一、前言
我们以一个示例开始:创建一个MD5哈希计算程序,使用C++库Poco。
这里使用CMake作为构建系统,但请记住:Conan可以使用任意构建系统,不局限于CMake。
确保当前使用的是Conan最新版本。
二、一个使用Poco库的MD5哈希计算程序
- 在文件夹中创建下面源文件:
md5.cpp
#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;
}
- 由于程序依赖到Poco库,我们可以到ConanCenter远程仓库查找,打开https://conan.io/center,在搜索框输入“poco”,将会看到以下不同版本:
poco/1.8.1
poco/1.9.3
poco/1.9.4
...
- 可以获取我们所需要的Poco引用,比如,检查1.9.4版本的元数据:
$ 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.
topics: ('conan', 'poco', 'building', 'networking', 'server'