Conan2: starting at a text book example

“From using libraries already packaged by Conan, to how to package your libraries and store them in a remote server alongside all the precompiled binaries.”

  1. Clone the sources of this example project from github, and open the simple_cmake_project directory:
> git clone https://github.com/conan-io/examples2.git
> cd examples2/tutorial/consuming_packages/simple_cmake_projectE:\XXXX\examples2\tutorial\consuming_packages\simple_cmake_project> tree /a /f
卷 文档 的文件夹 PATH 列表
卷序列号为 EXXX-XXXX
E:.
|   CMakeLists.txt
|   conanfile.txt
|
+---build
\---srcmain.c

main.c

#include <stdlib.h>
#include <stdio.h>
#include <string.h>#include <zlib.h>int main(void) {char buffer_in [256] = {"Conan is a MIT-licensed, Open Source package manager for C and C++ development, ""allowing development teams to easily and efficiently manage their packages and ""dependencies across platforms and build systems."};char buffer_out [256] = {0};z_stream defstream;defstream.zalloc = Z_NULL;defstream.zfree = Z_NULL;defstream.opaque = Z_NULL;defstream.avail_in = (uInt) strlen(buffer_in);defstream.next_in = (Bytef *) buffer_in;defstream.avail_out = (uInt) sizeof(buffer_out);defstream.next_out = (Bytef *) buffer_out;deflateInit(&defstream, Z_BEST_COMPRESSION);deflate(&defstream, Z_FINISH);deflateEnd(&defstream);printf("Uncompressed size is: %lu\n", strlen(buffer_in));printf("Compressed size is: %lu\n", strlen(buffer_out));printf("ZLIB VERSION: %s\n", zlibVersion());return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(compressor C)find_package(ZLIB REQUIRED)add_executable(${PROJECT_NAME} src/main.c)
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)
  1. conanfile.txt

This application relies on the Zlib library. Conan, by default, tries to install libraries from a remote server called ConanCenter. One can search there for libraries and also check the available versions. In this case, after checking the available versions for Zlib one of the latest versions: zlib/1.2.11 is chosed.
The easiest way to install the Zlib library and find it from this project with Conan is using a conanfile.txt file:

[requires]
zlib/1.2.11[generators]
CMakeDeps
CMakeToolchain

[requires] section is where we declare the libraries we want to use in the project, in this case, zlib/1.2.11.
[generators] section tells Conan to generate the files that the compilers or build systems will use to find the dependencies and build the project. In this case, as our project is based in CMake, we will use:
CMakeDeps to generate information about where the Zlib library files are installed and
CMakeToolchain to pass build information to CMake using a CMake toolchain file.

  1. Conan profile
    Besides the conanfile.txt, we need a Conan profile to build our project.
    Conan profiles allow users to define a configuration set for things like the compiler, build configuration, architecture, shared or static libraries, etc.
    Conan, by default, will not try to detect a profile automatically, so we need to create one.
    To let Conan try to guess the profile, based on the current operating system and installed tools, please run:
E:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project>conan profile detect --force
detect_api: Found msvc 17Detected profile:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.version=193
os=WindowsWARN: This profile is a guess of your environment, please check it.
WARN: The output of this command is not guaranteed to be stable and can change in future Conan versions.
WARN: Use your own profile files for stability.
Saving detected profile to C:\Users\XXXXX\.conan2\profiles\default

This will detect the operating system, build architecture and compiler settings based on the environment.
It will also set the build configuration as Release by default.
The generated profile will be stored in the Conan home folder with name default and will be used by Conan in all commands by default unless another profile is specified via the command line.

  1. conan install
    Use Conan to install Zlib and generate the files that CMake needs to find this library and build project. Those files will be generated in the folder build:
E:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project>conan install . --output-folder=build --build=missing======== Input profiles ========
Profile host:
[settings]
arch=x86_64
...
...
E:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project> tree /a /f
卷 文档 的文件夹 PATH 列表
卷序列号为 XXXX-XXXX
E:.
|   CMakeLists.txt
|   CMakeUserPresets.json
|   conanfile.txt
|
+---build
|       cmakedeps_macros.cmake
|       CMakePresets.json
|       conanbuild.bat
|       conanbuildenv-release-x86_64.bat
|       conandeps_legacy.cmake
|       conanrun.bat
|       conanrunenv-release-x86_64.bat
|       conan_toolchain.cmake
|       deactivate_conanbuild.bat
|       deactivate_conanrun.bat
|       FindZLIB.cmake
|       module-ZLIB-release-x86_64-data.cmake
|       module-ZLIB-Target-release.cmake
|       module-ZLIBTargets.cmake
|       ZLIB-release-x86_64-data.cmake
|       ZLIB-Target-release.cmake
|       ZLIBConfig.cmake
|       ZLIBConfigVersion.cmake
|       ZLIBTargets.cmake
|
\---srcmain.c

• Conan installed the Zlib library from the remote server, which should be the Conan Center server by default if the library is available. This server stores both the Conan recipes, which are the files that define how libraries must be built, and the binaries that can be reused so we don’t have to build from sources every time.

• Conan generated several files under the build folder. Those files were generated by both the CMakeToolchain and CMakeDeps generators we set in the conanfile.txt. CMakeDeps generates files so that CMake finds the Zlib library we have just downloaded. On the other side, CMakeToolchain generates a toolchain file for CMake so that we can transparently build our project with CMake using the same settings that we detected for our default profile.

  1. build and run compressor app
E:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project>cd buildE:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project\build>cmake .. -G "Visual Studio 17 2022" -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake
-- Using Conan toolchain: E:/XXXXX/examples2/tutorial/consuming_packages/simple_cmake_project/build/conan_toolchain.cmake
-- Conan toolchain: CMAKE_GENERATOR_TOOLSET=v143
-- Conan toolchain: C++ Standard 14 with extensions OFF
-- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.36.32532.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Conan: Target declared 'ZLIB::ZLIB'
-- Configuring done (4.0s)
-- Generating done (0.0s)
-- Build files have been written to: E:/XXXXX/examples2/tutorial/consuming_packages/simple_cmake_project/buildE:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project\build>cmake --build . --config Release
MSBuild version 17.6.3+07e294721 for .NET FrameworkChecking Build SystemBuilding Custom Rule E:/XXXXX/examples2/tutorial/consuming_packages/simple_cmake_project/CMakeLists.txtmain.cE:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project\build>cd Release
E:\XXXXX\examples2\tutorial\consuming_packages\simple_cmake_project\build\Release>compressor.exe
Uncompressed size is: 207
Compressed size is: 19
ZLIB VERSION: 1.2.11

References

  1. Conan Documentation --Release 2.0.17

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MySQL 运算符BETWEEN.NOT. BETWEEN.IN.NOT IN

MySQL 运算符 本章节我们主要介绍 MySQL 的运算符及运算符的优先级。 MySQL 主要有以下几种运算符&#xff1a; 算术运算符 MySQL 支持的算术运算符包括: 运算符作用加法–减法*乘法/ 或 DIV除法% 或 MOD取余 在除法运算和模运算中&#xff0c;如果除数为0&#xff0c;将是…

MySQL封装JDBC为工具类(JDBC简化)

1&#xff1a;在我们对一个表的增删改查中我们可以发现&#xff0c;如果一个表要进行增删改查四个操作时&#xff0c;我们可能要四个方法&#xff0c;四个方法中每一个方法都需要进行JDBC的连接&#xff0c;如果每一步都按照JdbcTemplate方式写的话可能会简化一点&#xff0c;但…

【GitHub项目推荐--推荐一个开源的任务管理工具(仿X书/X钉)】【转载】

推荐一个开源的任务管理工具&#xff0c;该工具会提供各类文档协作功能、在线思维导图、在线流程图、项目管理、任务分发、即时 IM&#xff0c;文件管理等等。该开源项目使用到 Vue、Element-UI、ECharts 等技术栈。 开源地址&#xff1a;www.github.com/kuaifan/dootask 预览地…

Ribbon 体系架构解析

前面已经介绍了服务治理相关组件&#xff0c;接下来趁热打铁&#xff0c;快速通关Ribbon&#xff01;前面我们了解了负载均衡的含义&#xff0c;以及客户端和服务端负载均衡模型&#xff0c;接下来我们就来看下SpringCloud 下的客户端负载均衡组件Ribbon 的特点以及工作模型。 …

【Linux】从C语言文件操作 到Linux文件IO | 文件系统调用

文章目录 前言一、C语言文件I/O复习文件操作&#xff1a;打开和关闭文件操作&#xff1a;顺序读写文件操作&#xff1a;随机读写stdin、stdout、stderr 二、承上启下三、Linux系统的文件I/O系统调用接口介绍open()close()read()write()lseek() Linux文件相关重点 复习C文件IO相…

【计算机网络】中小型校园网构建与配置

拓扑图配置文件传送门 Packet Tracer-中小型校园网配置布局文件文件 相关文章 【计算机网络】IP协议及动态路由算法 【计算机网络】Socket通信编程与传输协议分析 【计算机网络】网络应用通信基本原理 原理 1. Network 广域网&#xff0c;WAN Wide Area Network&#xff…

花式沉默Defender

编者注&#xff1a;本文仅供学习研究&#xff0c;严禁从事非法活动&#xff0c;任何后果由使用者本人负责。 前言 总结了一下现在还能用的关闭Defender的方法&#xff0c;部分是原创&#xff0c;一部分借鉴的大佬。觉得字多的同学可以直接跳过思路查看步骤进行实操。 修改注册…

再学http

HTTP状态码 1xx 信息性状态码 websocket upgrade 2xx 成功状态码 200 服务器已成功处理了请求204(没有响应体)206(范围请求 暂停继续下载) 3xx 重定向状态码 301(永久) &#xff1a;请求的页面已永久跳转到新的url302(临时) &#xff1a;允许各种各样的重定向&#xff0c;一般…

自动驾驶和智能座舱软件介绍(二)

作者 / 阿宝 编辑 / 阿宝 出品 / 阿宝1990 自动驾驶软件介绍 自动驾驶底层操作系统及软件架构 底层可以包括多种芯片&#xff0c;以太网通信中间件保证网络通信和不同OS任务分配的确定性 Automotive uC&#xff0c;单片机&#xff0c;如英飞凌AURIX&#xff0c;运行AUTOSARB…

Github 2024-01-28 开源项目日报Top10

根据Github Trendings的统计&#xff0c;今日(2024-01-28统计)共有10个项目上榜。根据开发语言中项目的数量&#xff0c;汇总情况如下&#xff1a; 开发语言项目数量Python项目3TypeScript项目2Rust项目1HTML项目1JavaScript项目1Cuda项目1C#项目1非开发语言项目1 Nuxt&#…

力扣0079单词搜索

单词搜索 难度&#xff1a;中等 题目描述&#xff1a; 给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中&#xff0c;返回 true &#xff1b;否则&#xff0c;返回 false 。 单词必须按照字母顺序&#xff0c;通过相邻的单元格内的字母构…

TypeSript教程基础用法(TS)

TypeScript基础语法 布尔值 TypeScript中可以使用boolean来表示这个变量是布尔值&#xff0c;可以赋值为true或者false。 let isDone: boolean false;数字 TypeScript里的所有数字都是浮点数&#xff0c;这些浮点数的类型是 number。除了支持十进制&#xff0c;还支持二进…

XSS_Labs靶场通关笔记

每一关的方法不唯一&#xff1b;可以结合源码进行分析后构造payload&#xff1b; 通关技巧&#xff08;四步&#xff09;&#xff1a; 1.输入内容看源码变化&#xff1b; 2.找到内容插入点&#xff1b; 3.测试是否有过滤&#xff1b; 4.构造payload绕过 第一关 构造paylo…

势态知感是一种主动的态势感知

势态知感是指主动观察和感知周围环境中存在的势态或态势变化的能力。势态指的是事物所呈现出来的动态特征和趋势。势态知感的主动性体现在人们通过观察、感知和分析过往的经验&#xff0c;来预测或捕捉到事物存在的势态&#xff0c;从而可以作出相应的决策和行动。 势态知感在…

8-Docker网络命令之prune

1.prune介绍 Docker网络命令prune是用来删除所有无用的网络 2.prune用法 docker network prune [参数] [rootcentos79 ~]# docker network prune --helpUsage: docker network prune [OPTIONS]Remove all unused networksOptions:--filter filter Provide filter values …

LightDB 24.1 UNION支持null类型匹配

背景介绍 在LightDB 24.1之前的版本&#xff0c;UNION null类型匹配会报错。 lightdbpostgres# select null l_zqlbmx2 union all select null l_zqlbmx2 union all select sysdate l_zqlbmx; ERROR: UNION types text and timestamp without time zone…

使用scyllaDb 或者cassandra存储聊天记录

一、使用scyllaDb的原因 目前开源的聊天软件主要还是使用mysql存储数据&#xff0c;数据量大的时候比较麻烦&#xff1b; 我打算使用scyllaDB存储用户的聊天记录&#xff0c;主要考虑的优点是&#xff1a; 1&#xff09;方便后期线性扩展服务器&#xff1b; 2&#xff09;p…

Redis数据类型及底层实现

文章目录 1.3.1 5种基本数据类型1.3.1.1 总结篇1.3.1.2 底层源码引入篇1.3.1.2.1 redis是字典数据库KV键值对到底是什么1.3.1.2.2 数据类型视角1.3.1.2.3 数据模型解析&#xff08;重点&#xff09;1.3.1.2.4 redisObjec1.3.1.2.5 SDS 1.3.1.3 String1.3.1.3.1 底层分析1.3.1.3…

uniCloud 免费版和商用版

概述 uniCloud为每个开发者提供一个免费的服务空间&#xff0c;更低门槛按量付费是serverless的特色&#xff0c;如果没有消耗硬件资源&#xff0c;就完全不用付款serverless比传统的云主机更便宜传统云主机一旦被攻击&#xff0c;高防价格非常昂贵。而uniCloud无需支付高防费…

k8s的图形化工具rancher

1、rancher&#xff1a;是一个开源的企业级多集群的k8s管理平台 2、rancher和k8s的区别 &#xff08;1&#xff09;都是为了容器的调度和编排系统 &#xff08;2&#xff09;但rancher不仅能够调度&#xff0c;还能管理k8s集群&#xff0c;自带监控&#xff08;普罗米修斯&a…