使用conan包 - 安装依赖项

使用conan包 - 安装依赖项

  • 主目录 conan Using packages
  • 1 Requires
  • 2 Optional user/channel
  • 3 Overriding requirements
  • 4 Generators
  • 5 Options

本文是基于对conan官方文档Installing dependencies的翻译而来, 更详细的信息可以去查阅conan官方文档。

This section shows how to setup your project and manage dependencies (i.e., install existing packages) with Conan.
本节将介绍如何使用 Conan 设置项目和管理依赖关系(即安装现有软件包)。

主目录 conan Using packages

  • Installing dependencies
    • Requires
    • Generators
    • Options
  • Using profiles
  • Workflows
    • Single configuration
    • Multi configuration
  • Debugging packages

In Getting started we used the conan install command to download the Poco library and build an example.
在 "Getting started "部分,我们使用 conan install 命令下载了 Poco 库并构建了一个示例。

If you inspect the conanbuildinfo.cmake file that was created when running conan install, you can see there that there are many CMake variables declared. For example CONAN_INCLUDE_DIRS_ZLIB, that defines the include path to the zlib headers, and CONAN_INCLUDE_DIRS that defines include paths for all dependencies headers.
如果检查运行 conan install 时创建的 conanbuildinfo.cmake 文件,可以看到其中声明了许多 CMake 变量。例如,CONAN_INCLUDE_DIRS_ZLIB 定义了 zlib 头文件的包含路径,而 CONAN_INCLUDE_DIRS 则定义了所有依赖头文件的包含路径。
在这里插入图片描述
If you check the full path that each of these variables defines, you will see that it points to a folder under your folder. Together, these folders are the local cache. This is where package recipes and binary packages are stored and cached, so they don’t have to be retrieved again. You can inspect the local cache with conan search, and remove packages from it with conan remove command.
如果查看这些变量定义的完整路径,你会发现它们都指向 <userhome> 文件夹下的一个文件夹。这些文件夹就是本地缓存。这就是软件包recipes和二进制软件包的存储和缓存位置,因此无需再次检索。您可以使用 conan search 查看本地缓存,也可以使用 conan remove 命令删除缓存中的软件包。

If you navigate to the folders referenced in conanbuildinfo.cmake you will find the headers and libraries for each package.
如果您浏览 conanbuildinfo.cmake 中引用的文件夹,就会发现每个软件包的头文件和库。

If you execute a conan install poco/1.9.4@ command in your shell, Conan will download the Poco package and its dependencies (openssl/1.0.2t and zlib/1.2.11) to your local cache and print information about the folder where they are installed. While you can install each of your dependencies individually like that, the recommended approach for handling dependencies is to use a conanfile.txt file. The structure of conanfile.txt is described below.
如果在 shell 中执行 conan install poco/1.9.4@ 命令,Conan 会将 Poco 软件包及其依赖包(openssl/1.0.2tzlib/1.2.11)下载到本地缓存,并打印安装文件夹的相关信息。您可以像这样单独安装每个依赖项,但处理依赖项的推荐方法是使用 conanfile.txt 文件。conanfile.txt 的结构如下描述所示。

1 Requires

The required dependencies should be specified in the [requires] section. Here is an example:
应在 [requires] 部分指定所需的依赖项。下面是一个例子:

[requires]
mypackage/1.0.0@company/stable

Where:

  • mypackage is the name of the package which is usually the same as the project/library.
  • mypackage 是软件包的名称,通常与项目/库的名称相同。
  • 1.0.0 is the version which usually matches that of the packaged project/library. This can be any string; it does not have to be a number, so, for example, it could indicate if this is a “develop” or “master” version. Packages can be overwritten, so it is also OK to have packages like “nightly” or “weekly”, that are regenerated periodically.
  • 1.0.0 是版本,通常与打包项目/库的版本一致。它可以是任何字符串,不一定是数字,例如,它可以表示这是 "develop "还是 "master "版本。软件包可以被覆盖,因此也可以使用 "nightly "或 "weekly "这样的软件包,它们会定期重新生成。
  • company is the owner of this package. It is basically a namespace that allows different users to have their own packages for the same library with the same name.
  • company是该软件包的所有者。它基本上是一个命名空间,允许不同用户为同一个库拥有自己的同名软件包。
  • stable is the channel. Channels provide another way to have different variants of packages for the same library and use them interchangeably. They usually denote the maturity of the package as an arbitrary string such as “stable” or “testing”, but they can be used for any purpose such as package revisions (e.g., the library version has not changed, but the package recipe has evolved).
  • stable就是channelchannel为同一库提供了另一种拥有不同变体软件包并可互换使用的方式。它们通常以任意字符串(如 "stable "或 “testing”)表示软件包的成熟度,但也可用于任何目的,如软件包的修订(例如,库的版本没有变化,但软件包的recipe发生了变化)。

2 Optional user/channel

If the package was created and uploaded without specifying the user and channel you can omit the user/channel when specifying a reference:
如果创建和上传软件包时没有指定userchannel,则可以在指定引用时省略user/channel

[requires]
packagename/1.2.0

3 Overriding requirements

You can specify multiple requirements and override transitive “require’s requirements”. In our example, Conan installed the Poco package and all its requirements transitively:
您可以指定多个需求,并覆盖传递性的 “require’s requirements”。在我们的示例中,conan安装了 Poco 软件包及其所有需求:

  • openssl/1.0.2t
  • zlib/1.2.11

Tip
This is a good example of overriding requirements given the importance of keeping the OpenSSL library updated.
鉴于保持更新 OpenSSL 库的重要性,这是一个overriding requirements的好例子。
Consider that a new release of the OpenSSL library has been released, and a new corresponding Conan package is available. In our example, we do not need to wait until pocoproject (the author) generates a new package of POCO that includes the new OpenSSL library.
考虑到 OpenSSL 库的新版本已经发布,相应的新 Conan 软件包也已可用。在我们的示例中,我们不需要等到 pocoproject(作者)生成包含新 OpenSSL 库的 POCO 新软件包。

We can simply enter the new version in the [requires] section:
我们只需在【requires】部分输入新版本即可:

[requires]
poco/1.9.4
openssl/1.0.2u

The second line will override the openssl/1.0.2t required by POCO with the currently non-existent openssl/1.0.2u.
第二行将用目前不存在的 openssl/1.0.2u 覆盖 POCO 所需的 openssl/1.0.2t。

Another example in which we may want to try some new zlib alpha features: we could replace the zlib requirement with one from another user or channel.
另一个例子是,我们可能想尝试一些新的 zlib alpha 功能:我们可以用另一个user 或 channel的 zlib 需求来替换。

[requires]
poco/1.9.4
openssl/1.0.2u
zlib/1.2.11@otheruser/alpha

Note
You can use environment variable CONAN_ERROR_ON_OVERRIDE to raise an error for every overridden requirement not marked explicitly with the override keyword.
你可以使用环境变量 CONAN_ERROR_ON_OVERRIDE,为每一个未明确标记覆盖关键字的覆盖需求引发错误。

4 Generators

Conan reads the [generators] section from conanfile.txt and creates files for each generator with all the information needed to link your program with the specified requirements. The generated files are usually temporary, created in build folders and not committed to version control, as they have paths to local folders that will not exist in another machine. Moreover, it is very important to highlight that generated files match the given configuration (Debug/Release, x86/x86_64, etc) specified when running conan install. If the configuration changes, the files will change accordingly.
Conan 会读取 conanfile.txt 中的 [generators] 部分,并为每个生成器(generator)创建文件,其中包含将程序与指定要求链接到您自己程序所需的所有信息。生成的文件通常是临时文件,创建在构建文件夹中,不会提交到版本控制中,因为它们的路径指向本地文件夹,而这些文件夹在另一台机器中并不存在。此外,必须确保生成的文件与运行 conan install 时指定的配置(Debug/Release、x86/x86_64 等)相匹配。如果配置更改,文件也会相应更改。

For a full list of generators, please refer to the complete generators reference.、
有关generators的完整列表,请参阅完整的generators参考资料。

5 Options

We have already seen that there are some settings that can be specified during installation. For example, conan install .. -s build_type=Debug. These settings are typically a project-wide configuration defined by the client machine, so they cannot have a default value in the recipe. For example, it doesn’t make sense for a package recipe to declare “Visual Studio” as a default compiler because that is something defined by the end consumer, and unlikely to make sense if they are working in Linux.
我们已经看到,在安装过程中可以指定一些设置。例如,conan install ... -s build_type=Debug。这些设置通常是由客户机器定义的项目范围内的配置,因此它们在recipe中不可能有默认值。例如,在软件包配方中将 "Visual Studio "声明为默认编译器是不合理的,因为这是由最终用户定义的,如果他们在 Linux 中工作,就不可能将其作为默认编译器。

On the other hand, options are intended for package specific configuration that can be set to a default value in the recipe. For example, one package can define that its default linkage is static, and this is the linkage that should be used if consumers don’t specify otherwise.
另一方面,options用于软件包的特定配置,可以在recipe中设置为默认值。例如,一个软件包可以定义其默认链接为静态链接,如果消费者没有另行指定,就应该使用这种链接。

Note
You can see the available options for a package by inspecting the recipe with conan get <reference> command:
使用 conan get <reference> 命令查看配方,可以看到软件包的可用选项:

$ conan get poco/1.9.4@

To see only specific fields of the recipe you can use the conan inspect command instead:
如果只想查看配方的特定字段,可以使用 conan inspect 命令:

$ conan inspect poco/1.9.4@ -a=options
$ conan inspect poco/1.9.4@ -a=default_options

For example, we can modify the previous example to use dynamic linkage instead of the default one, which was static, by editing the [options] section in conanfile.txt:
例如,我们可以通过编辑 conanfile.txt 中的 [options] 部分,修改前面的示例,使用动态链接,而不是默认的静态链接:

[requires]
poco/1.9.4

[generators]
cmake

[options]
poco:shared=True # PACKAGE:OPTION=VALUE
openssl:shared=True

Install the requirements and compile from the build folder (change the CMake generator if not in Windows):
安装requirements并从构建文件夹编译(如果不是在 Windows 系统中,请更改 CMake 生成器):

$ conan install ..
$ cmake .. -G "Visual Studio 14 Win64"
$ cmake --build . --config Release

As an alternative to defining options in the conanfile.txt file, you can specify them directly in the command line:
除了在 conanfile.txt 文件中定义选项外,还可以直接在命令行中指定选项:

$ conan install .. -o poco:shared=True -o openssl:shared=True
# or even with wildcards, to apply to many packages
$ conan install .. -o *:shared=True

Conan will install the binaries of the shared library packages, and the example will link with them. You can again inspect the different binaries installed. For example, conan search zlib/1.2.11@.
Conan 将安装共享库软件包的二进制文件,示例将与它们链接。你可以再次检查安装的不同二进制文件。例如,Conan 搜索 zlib/1.2.11@。

Finally, launch the executable:
最后,加载可执行文件:

$ ./bin/md5

What happened? It fails because it can’t find the shared libraries in the path. Remember that shared libraries are used at runtime, so the operating system, which is running the application, must be able to locate them.
发生了什么?失败的原因是在路径中找不到共享库。请记住,共享库是在运行时使用的,因此运行应用程序的操作系统必须能够找到它们。

We could inspect the generated executable, and see that it is using the shared libraries. For example, in Linux, we could use the objdump tool and see the Dynamic section:
我们可以检查生成的可执行文件,看看它是否使用了共享库。例如,在 Linux 中,我们可以使用 objdump 工具查看动态部分:

$ cd bin
$ objdump -p md5
...
Dynamic Section:
 NEEDED               libPocoUtil.so.31
 NEEDED               libPocoXML.so.31
 NEEDED               libPocoJSON.so.31
 NEEDED               libPocoMongoDB.so.31
 NEEDED               libPocoNet.so.31
 NEEDED               libPocoCrypto.so.31
 NEEDED               libPocoData.so.31
 NEEDED               libPocoDataSQLite.so.31
 NEEDED               libPocoZip.so.31
 NEEDED               libPocoFoundation.so.31
 NEEDED               libpthread.so.0
 NEEDED               libdl.so.2
 NEEDED               librt.so.1
 NEEDED               libssl.so.1.0.0
 NEEDED               libcrypto.so.1.0.0
 NEEDED               libstdc++.so.6
 NEEDED               libm.so.6
 NEEDED               libgcc_s.so.1
 NEEDED               libc.so.6

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/193678.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

Python---可变和非可变数据类型

在Python中一共有7种数据类型&#xff1a; 数值&#xff08;int整型、float浮点类型&#xff09;、bool类型&#xff08;True和False&#xff09;、字符串类型&#xff08;str&#xff09;、元组&#xff08;tuple 1,2,3&#xff09;、列表&#xff08;list [1, 2, 3]&#xf…

6款AI工具网站,赶紧收藏,以备不时之需

1、海鲸AI-支持AI对话、AI文档解析、AI绘画 https://www.atalk-ai.com 海鲸AI是一个AI应用网站&#xff0c;同时支持PC和移动端&#xff0c;它在一个页面上提供了多种模型&#xff08;GPT3&#xff0c;GPT4&#xff0c;文心一言&#xff0c;通义千问&#xff0c;智谱AI&#…

Figma 插件学习(二)- 常用属性和方法

一. 如何调试figma插件 Plugins > Development > Show/Hide console 打开控制台即可开始调试 二.节点类型 根据不同的节点类型&#xff0c;也是会有不同的方法和属性&#xff0c;介绍几个常用节点类型 1.FrameNode 框架节点是用于定义布局层次结构的容器。它类似于HTM…

file_get_contents() 函数详解与使用

概述 在PHP中&#xff0c;file_get_contents() 函数是一个强大的工具&#xff0c;它既可以用于读取本地文件的内容&#xff0c;也可以用于发起 HTTP 请求获取远程资源。本文将详细介绍 file_get_contents() 函数的两种主要用途&#xff0c;并探讨如何充分利用这个函数。 1. 文…

Failed to load resource: the server responded with a status of 404 ()

路径问题&#xff1a; 路径省略前面的http://localhost:8080/ 就行了。

五子棋游戏

import pygame #导入pygame模块 pygame.init()#初始化 screen pygame.display.set_mode((750,750))#设置游戏屏幕大小 running True#建立一个事件 while running:#事件运行for event in pygame.event.get():if event.type pygame.QUIT:#当点击事件后退出running False #事…

数据结构 / day04 作业

1. 单链表任意位置删除, 单链表任意位置修改, 单链表任意位置查找, 单链表任意元素查找, 单链表任意元素修改, 单链表任意元素删除, 单链表逆置 // main.c#include "head.h"int main(int argc, const char *argv[]) {Linklist headNULL; //head 是头指针// printf(&q…

ClickHouse中的物化视图

技术主题 技术原理 物化视图&#xff08;Materialized View&#xff09;是一种预先计算并缓存结果的视图&#xff0c;存储在磁盘上自动更新&#xff0c;空间换时间的思路。物化视图是一种优化技术&#xff0c;本质上就是为了加速查询操作&#xff0c;降低系统负载&#xff0c…

Java远程连接本地开源分布式搜索引擎ElasticSearch

文章目录 前言1. Windows 安装 Cpolar2. 创建Elasticsearch公网连接地址3. 远程连接Elasticsearch4. 设置固定二级子域名 前言 简单几步,结合Cpolar内网穿透工具实现Java远程连接操作本地Elasticsearch。 什么是elasticsearch&#xff1f;一个开源的分布式搜索引擎&#xff0…

第1章 爬虫基础

目录 1. HTTP 基本原理1.1 URI 和 URL1.2 HTTP 和 HTTPS1.3 请求1.3.1 请求方法1.3.2 请求的网址1.3.3 请求头1.3.4 请求体 1.4 响应1.4.1 响应状态码1.4.2 响应头1.4.3 响应体 2. Web 网页基础2.1 网页的组成2.1.1 HTML2.1.2 CSS2.1.3 JavaScript 2.2 网页的结构2.3 节点树及节…

160 相交链表

解题思路&#xff1a; \qquad 若两个链表a, b相交&#xff0c;则它们之间的区别就仅在于相交节点之前的部分&#xff08;其实任意两个链表最终都会相交&#xff0c;最坏相交于NULL节点&#xff09;。一开始的思路&#xff1a; \qquad\qquad\qquad 1、找到两个链表较长的那个&…

UE5 - 虚幻引擎各模块流程图

来自虚幻官方的一些资料&#xff0c;分享一下&#xff1b; 一些模块的流程图&#xff0c;比如动画模块&#xff1a; 或角色相关流程&#xff1a; 由于图片比较大&#xff0c;上传到了网络&#xff0c;可自取&#xff1a; 链接&#xff1a;https://pan.baidu.com/s/1BQ2KiuP08c…

【JavaScript框架】2024年需要学习的顶级JavaScript框架:Blitz、SolidJS、Svelte等

如今&#xff0c;Web开发人员面临两大问题。 第一个是如何自动化繁琐的web开发工作。要为标准web应用程序设置一个项目&#xff0c;您必须花费宝贵的时间学习用于常见任务的几个库&#xff0c;如身份验证和数据库处理&#xff0c;并将它们捆绑在一起。第二个问题是如何使网络应…

数据增强让模型更健壮

在做一些图像分类训练任务时,我们经常会遇到一个很尴尬的情况,那就是: 明明训练数据集中有很多可爱猫咪的照片,但是当我们给训练好的模型输入一张戴着头盔的猫咪进行测试时,模型就不认识了,或者说识别精度很低。 很明显,模型的泛化能力太差,难道戴着头盔的猫咪就不是猫…

MATLAB的rvctools工具箱熟悉运动学【机械臂机器人示例】

1、rvctools下载安装 rvctools下载地址&#xff1a;rvctools下载 截图如下&#xff0c;点击红色箭头指示的“Download Shared Folder” 即可下载 下载之后进行解压&#xff0c;解压到D:\MATLAB\toolbox这个工具箱目录&#xff0c;这个安装路径根据自己的情况来选择&#xff0c…

案例030:基于微信小程序的英语学习交流平台

文末获取源码 开发语言&#xff1a;Java 框架&#xff1a;SSM JDK版本&#xff1a;JDK1.8 数据库&#xff1a;mysql 5.7 开发软件&#xff1a;eclipse/myeclipse/idea Maven包&#xff1a;Maven3.5.4 小程序框架&#xff1a;uniapp 小程序开发软件&#xff1a;HBuilder X 小程序…

详解Java中的泛型(泛型的语法,擦除机制,泛型的上界)

目录 一.什么是泛型 二.Java中为什么要使用泛型 三.泛型的语法 四.泛型类的使用 五.泛型的编译机制&#xff08;擦除机制&#xff09; 六.泛型的上界 一.什么是泛型 泛型&#xff08;Generics&#xff09;是Java SE 5中引入的一个新特性&#xff0c;可以使Java中的类和方…

SpringBoot : ch07 整合websocket

前言 当涉及到在Spring Boot应用程序中整合WebSocket时&#xff0c;我们可以使用Spring框架提供的功能来实现实时双向通信。WebSocket是一种在Web浏览器和服务器之间进行全双工通信的协议&#xff0c;它允许服务器主动向客户端发送消息&#xff0c;而不需要客户端发起请求。 …

23种经典设计模式:单例模式篇(C++)

前言&#xff1a; 博主将从此篇单例模式开始逐一分享23种经典设计模式&#xff0c;并结合C为大家展示实际应用。内容将持续更新&#xff0c;希望大家持续关注与支持。 什么是单例模式&#xff1f; 单例模式是设计模式的一种&#xff08;属于创建型模式 (Creational Pa…

多功能智慧路灯系统整体解决方案介绍

在不改变现有城市景观的前提下&#xff0c;利用现有路灯改造&#xff0c;或新建多功能叁仟智慧路灯的方法&#xff0c;可实现城市无线网络、视频监控、物联传感网络、新能源充电系统、网格信息化管理的全覆盖&#xff0c;有效解决信息化设备选址难、取电难等问题。在目前无线通…
最新文章