当前位置: 首页 > news >正文

使用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.31NEEDED               libPocoXML.so.31NEEDED               libPocoJSON.so.31NEEDED               libPocoMongoDB.so.31NEEDED               libPocoNet.so.31NEEDED               libPocoCrypto.so.31NEEDED               libPocoData.so.31NEEDED               libPocoDataSQLite.so.31NEEDED               libPocoZip.so.31NEEDED               libPocoFoundation.so.31NEEDED               libpthread.so.0NEEDED               libdl.so.2NEEDED               librt.so.1NEEDED               libssl.so.1.0.0NEEDED               libcrypto.so.1.0.0NEEDED               libstdc++.so.6NEEDED               libm.so.6NEEDED               libgcc_s.so.1NEEDED               libc.so.6

相关文章:

使用conan包 - 安装依赖项

使用conan包 - 安装依赖项 主目录 conan Using packages1 Requires2 Optional user/channel3 Overriding requirements4 Generators5 Options 本文是基于对conan官方文档Installing dependencies的翻译而来&#xff0c; 更详细的信息可以去查阅conan官方文档。 This section s…...

【数据库设计和SQL基础语法】--数据库设计基础--数据规范化和反规范化

一、 数据规范化 1.1 数据规范化的概念 定义 数据规范化是数据库设计中的一种方法&#xff0c;通过组织表结构&#xff0c;减少数据冗余&#xff0c;提高数据一致性和降低更新异常的过程。这一过程确保数据库中的数据结构遵循一定的标准和规范&#xff0c;使得数据存储更加高…...

复亚智能交通无人机:智慧交通解决方案大公开

城市的现代化发展离不开高效的交通管理规划。传统的交通管理系统庞大繁琐&#xff0c;交警在执行任务时存在安全隐患。在这一背景下&#xff0c;复亚智能交通无人机应运而生&#xff0c;成为智慧交通管理中的重要组成部分。交通无人机凭借其高灵活性、低成本、高安全性等特点&a…...

MYSQL 及 SQL 注入

文章目录 前言什么是sql注入防止SQL注入Like语句中的注入后言 前言 hello world欢迎来到前端的新世界 &#x1f61c;当前文章系列专栏&#xff1a;Mysql &#x1f431;‍&#x1f453;博主在前端领域还有很多知识和技术需要掌握&#xff0c;正在不断努力填补技术短板。(如果出现…...

古埃及金字塔的修建

从理论上说&#xff0c;古埃及人完全有能力设计并建造出充满各种奇妙细节的胡夫金字塔&#xff0c;但后世还是不断涌现出质疑之声&#xff0c;原因倒也简单&#xff0c;那就是胡夫金字塔实在太大了。据推算&#xff0c;整座金字塔使用大约230万块巨石&#xff0c;总质量可达约5…...

Android 13.0 系统settings系统属性控制一级菜单显示隐藏

1.概述 在13.0的系统rom定制化开发中,系统settings的一级菜单有些在客户需求中需要去掉不显示,所以就需要通过系统属性来控制显示隐藏, 从而达到控制一级菜单的显示的目的,而系统settings是通过静态加载的方式负责显示隐藏,接下来就来实现隐藏显示一级菜单的 功能实现 2.…...

STM32 寄存器配置笔记——USART配置中断接收乒乓缓存处理

一、概述 本文主要介绍如何配置USART接收中断&#xff0c;使用乒乓缓存的设计接收数据并将其回显在PC 串口工具上。以stm32f10为例&#xff0c;配置USART1 9600波特率。具体配置参考上一章节STM32 寄存器配置笔记——USART配置 打印。 乒乓缓存的设计应用场景&#xff1a;当后面…...

第二十一章 解读XML与JSON文件格式(工具)

XML XML tree and elements 将XML文档解析为树&#xff08;tree&#xff09; 我们先从基础讲起。XML是一种结构化、层级化的数据格式&#xff0c;最适合体现XML的数据结构就是树。ET提供了两个对象&#xff1a;ElementTree将整个XML文档转化为树&#xff0c;Element则代表着…...

Web 自动化神器 TestCafe(三)—用例编写篇

一、用例编写基本规范 1、 fixture 测试夹具 使用 TestCafe 编写测试用例&#xff0c;必须要先使用 fixture 声明一个测试夹具&#xff0c;然后在这个测试夹具下编写测试用例&#xff0c;在一个编写测试用例的 js 或 ts 文件中&#xff0c;可以声明多个测试夹具 fixture(测试…...

Redis 基本命令—— 超详细操作演示!!!

内存数据库 Redis7—— Redis 基本命令 三、Redis 基本命令&#xff08;下&#xff09;3.8 benchmark 测试工具3.9 简单动态字符串SDS3.10 集合的底层实现原理3.11 BitMap 操作命令3.12 HyperLogLog 操作命令3.13 Geospatial 操作命令3.14 发布/订阅命令3.15 Redis 事务 四、Re…...

Linux:centOS常用命令

CentOS是一种基于Red Hat Enterprise Linux&#xff08;RHEL&#xff09;的开源操作系统&#xff0c;因此与其他基于Linux的系统共享很多相似的命令。以下是一些在CentOS上常用的命令 件和目录操作: ls: 列出目录内容。cd: 切换目录。pwd: 显示当前工作目录。mkdir: 创建目录…...

数据结构-二叉树(1)

1.树概念及结构 1.1树的概念 树是一种非线性的数据结构&#xff0c;它是由n&#xff08;n>0&#xff09;个有限结点组成一个具有层次关系的集合。把它叫做树是因为它看起来像一棵倒挂的树&#xff0c;也就是说它是根朝上&#xff0c;而叶朝下的。 1.有一个特殊的结点&…...

SpringBoot——国际化

优质博文&#xff1a;IT-BLOG-CN 一、Spring 编写国际化时的步骤 【1】编写国际化配置文件&#xff1b; 【2】使用ResourceBundleMessageSource管理国际化资源文件&#xff1b; 【3】在页面使用ftp:message取出国际化内容&#xff1b; 二、SpringBoot编写国际化步骤 【1】创…...

shell 条件语句 if case

目录 测试 test测试文件的表达式 是否成立 格式 选项 比较整数数值 格式 选项 字符串比较 常用的测试操作符 格式 逻辑测试 格式 且 &#xff08;全真才为真&#xff09; 或 &#xff08;一真即为真&#xff09; 常见条件 双中括号 [[ expression ]] 用法 &…...

C语言:写一个函数,实现3*3矩阵的转置(指针)

分析&#xff1a; 在主函数 main 中&#xff0c;定义一个 3x3 的整型数组 a&#xff0c;并定义一个指向整型数组的指针 p。然后通过循环结构和 scanf 函数&#xff0c;从标准输入中读取用户输入的 3x3 矩阵的值&#xff0c;并存储到数组 a 中。 接下来&#xff0c;调用 mov…...

STL pair源码分析

STL pair源码分析 pair是STL中提供的一个简单的struct&#xff0c;用来处理类型不同的一对值&#xff0c;是非常常用的数据结构。这一对值是以public的形式暴露出来的&#xff0c;直接通过first和second就能访问。我们以MSVC提供的STL源码为例&#xff0c;分析pair的具体实现。…...

【开源】基于Vue和SpringBoot的农家乐订餐系统

项目编号&#xff1a; S 043 &#xff0c;文末获取源码。 \color{red}{项目编号&#xff1a;S043&#xff0c;文末获取源码。} 项目编号&#xff1a;S043&#xff0c;文末获取源码。 目录 一、摘要1.1 项目介绍1.2 项目录屏 二、功能模块2.1 用户2.2 管理员 三、系统展示四、核…...

MyBatis 操作数据库(入门)

一&#xff1a;MyBatis概念 (1)MyBatis &#x1f497;MyBatis是一款优秀的持久层框架&#xff0c;用于简化JDBC的开发 (2)持久层 1.持久层 &#x1f49c;持久层&#xff1a;持久化操作的层&#xff0c;通常指数据访问层(dao)&#xff0c;是用来操作数据库的 2.持久层的规范 ①…...

JVM——垃圾回收器(G1,JDK9默认为G1垃圾回收器)

1.G1垃圾回收器 JDK9之后默认的垃圾回收器是G1&#xff08;Garbage First&#xff09;垃圾回收器。 Parallel Scavenge关注吞吐量&#xff0c;允许用户设置最大暂停时间 &#xff0c;但是会减少年轻代可用空间的大小。 CMS关注暂停时间&#xff0c;但是吞吐量方面会下降。 而G1…...

多模态——使用stable-video-diffusion将图片生成视频

多模态——使用stable-video-diffusion将图片生成视频 0. 内容简介1. 运行环境2. 模型下载3. 代码梳理3.1 修改yaml文件中的svd路径3.2 修改DeepFloyDataFiltering的vit路径3.3 修改open_clip的clip路径3.4 代码总体结构 4. 资源消耗5. 效果预览 0. 内容简介 近期&#xff0c;…...

web vue 项目 Docker化部署

Web 项目 Docker 化部署详细教程 目录 Web 项目 Docker 化部署概述Dockerfile 详解 构建阶段生产阶段 构建和运行 Docker 镜像 1. Web 项目 Docker 化部署概述 Docker 化部署的主要步骤分为以下几个阶段&#xff1a; 构建阶段&#xff08;Build Stage&#xff09;&#xff1a…...

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする

日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする 1、前言(1)情况说明(2)工程师的信仰2、知识点(1) にする1,接续:名词+にする2,接续:疑问词+にする3,(A)は(B)にする。(2)復習:(1)复习句子(2)ために & ように(3)そう(4)にする3、…...

深入理解JavaScript设计模式之单例模式

目录 什么是单例模式为什么需要单例模式常见应用场景包括 单例模式实现透明单例模式实现不透明单例模式用代理实现单例模式javaScript中的单例模式使用命名空间使用闭包封装私有变量 惰性单例通用的惰性单例 结语 什么是单例模式 单例模式&#xff08;Singleton Pattern&#…...

QT: `long long` 类型转换为 `QString` 2025.6.5

在 Qt 中&#xff0c;将 long long 类型转换为 QString 可以通过以下两种常用方法实现&#xff1a; 方法 1&#xff1a;使用 QString::number() 直接调用 QString 的静态方法 number()&#xff0c;将数值转换为字符串&#xff1a; long long value 1234567890123456789LL; …...

css3笔记 (1) 自用

outline: none 用于移除元素获得焦点时默认的轮廓线 broder:0 用于移除边框 font-size&#xff1a;0 用于设置字体不显示 list-style: none 消除<li> 标签默认样式 margin: xx auto 版心居中 width:100% 通栏 vertical-align 作用于行内元素 / 表格单元格&#xff…...

项目部署到Linux上时遇到的错误(Redis,MySQL,无法正确连接,地址占用问题)

Redis无法正确连接 在运行jar包时出现了这样的错误 查询得知问题核心在于Redis连接失败&#xff0c;具体原因是客户端发送了密码认证请求&#xff0c;但Redis服务器未设置密码 1.为Redis设置密码&#xff08;匹配客户端配置&#xff09; 步骤&#xff1a; 1&#xff09;.修…...

佰力博科技与您探讨热释电测量的几种方法

热释电的测量主要涉及热释电系数的测定&#xff0c;这是表征热释电材料性能的重要参数。热释电系数的测量方法主要包括静态法、动态法和积分电荷法。其中&#xff0c;积分电荷法最为常用&#xff0c;其原理是通过测量在电容器上积累的热释电电荷&#xff0c;从而确定热释电系数…...

浪潮交换机配置track检测实现高速公路收费网络主备切换NQA

浪潮交换机track配置 项目背景高速网络拓扑网络情况分析通信线路收费网络路由 收费汇聚交换机相应配置收费汇聚track配置 项目背景 在实施省内一条高速公路时遇到的需求&#xff0c;本次涉及的主要是收费汇聚交换机的配置&#xff0c;浪潮网络设备在高速项目很少&#xff0c;通…...

LangChain知识库管理后端接口:数据库操作详解—— 构建本地知识库系统的基础《二》

这段 Python 代码是一个完整的 知识库数据库操作模块&#xff0c;用于对本地知识库系统中的知识库进行增删改查&#xff08;CRUD&#xff09;操作。它基于 SQLAlchemy ORM 框架 和一个自定义的装饰器 with_session 实现数据库会话管理。 &#x1f4d8; 一、整体功能概述 该模块…...

三分算法与DeepSeek辅助证明是单峰函数

前置 单峰函数有唯一的最大值&#xff0c;最大值左侧的数值严格单调递增&#xff0c;最大值右侧的数值严格单调递减。 单谷函数有唯一的最小值&#xff0c;最小值左侧的数值严格单调递减&#xff0c;最小值右侧的数值严格单调递增。 三分的本质 三分和二分一样都是通过不断缩…...