conan2 基础入门(04)-指定编译器(gcc为例)

conan2 基础入门(04)-指定编译器(gcc为例)

文章目录

  • conan2 基础入门(04)-指定编译器(gcc为例)
  • ⭐准备
    • 生成`profile`文件
    • 预备文件和Code
  • ⭐使用
    • 指令预览
    • 正确执行结果
    • 可能出现的问题
  • ⭐具体讲解
    • conan
    • cmake
  • END
    • settings.yml

⭐准备

生成profile文件

# 生成默认profile文件,名字为`default`
# --force 表示强制生成,即若原来有`default`会被覆盖
# --name 表示指定生成名称
conan profile detect
conan profile detect --force
conan profile detect --name <指定名称># 查看名为`default`的profile文件的路径
conan profile path default
conan profile path <名称># 查看已经存在的eprofile
conan profile list

预备文件和Code

profile文件:mygcc

可以用命令生成,也可以直接复制一份已存在的profile,或者直接自己新建一个空白文件都行。

并修改成如下的配置,注意,请根据自己平台的gcc进行配置。

注意:不同编译器的具体compiler参数是不一样的。具体参见配置目录下的settings.yml

conan profile detect --name "mygcc"
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.version=11
compiler.libcxx=libstdc++11
os=Windows
# 本文使用gcc版本
gcc (x86_64-posix-seh-rev3, Built by MinGW-W64 project) 11.2.0

文件名预览

:.
│  CMakeLists.txt
│  conanfile.txt
└─ main.cpp

main.cpp

#include <iostream>#include "zlib.h"void test_env() {std::cout << ">>>" << __func__ << std::endl;std::cout << "sizeof(void*) = " << sizeof(void *) << std::endl;
#if defined(__VERSION__)std::cout << "__VERSION__ = " << __VERSION__ << std::endl;
#elif defined(_MSC_VER)std::cout << "_MSC_VER = " << _MSC_VER << std::endl;
#endif
}void test_zlib(void) {std::cout << ">>>" << __func__ << std::endl;char buffer_in[256] = {"Conan is a MIT-licensed, Open Source package manager for C and C++ development""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());
}int main(void) {test_env();test_zlib();
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(mydemo CXX)set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)find_package(ZLIB REQUIRED)add_executable(${PROJECT_NAME} main.cpp)target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)

conanfile.txt

[requires]
zlib/1.3.1[generators]
CMakeDeps
CMakeToolchain

⭐使用

指令预览

流程化指令,run.bat

如果你和上文中的代码和配置文件编写一致,请无脑直接操作以下命令。

conan install . --output-folder=build --build=missing --profile:host=mygcc --profile:build=mygcccd buildcmake .. -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" -DCMAKE_BUILD_TYPE="Release"cmake --build . --config Releasecd ../binmydemo.exe

正确执行结果

>>>test_env
sizeof(void*) = 8
__VERSION__ = 11.2.0
>>>test_zlib
Uncompressed size is: 231
Compressed size is: 19
ZLIB VERSION: 1.3.1

可能出现的问题

  • profile文件的参数错误,见附录
  • 有中文路径
  • 指令缺失
  • release&debug模式没匹配

⭐具体讲解

conan

指定profile

在install命令下添加--profile

conan install . --output-folder=build --build=missing --profile=mygcc
conan install . --output-folder=build --build=missing --profile:host=mygcc --profile:build=mygcc

这里的第二条分别制定了host和build

  • host 表示目标平台

  • build 表示当前平台

一般这个在交叉编译时非常重要。在本示例中可以不指定。

若不指定,经测试host为mygcc配置,build为default状态。

cmake

这里使用mingw32-make。注意在生成时区别于使用msvc时,需要指定-DCMAKE_BUILD_TYPE="Release"

cmake .. -G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE="conan_toolchain.cmake" -DCMAKE_BUILD_TYPE="Release"cmake --build . --config Release



END

settings.yml

# 在配置home下的 `settings.yml`
conan config homeC:\Users\{用户名}\.conan2\settings.yml
# This file was generated by Conan. Remove this comment if you edit this file or Conan
# will destroy your changes.
os:Windows:subsystem: [null, cygwin, msys, msys2, wsl]WindowsStore:version: ["8.1", "10.0"]WindowsCE:platform: [ANY]version: ["5.0", "6.0", "7.0", "8.0"]Linux:iOS:version: &ios_version["7.0", "7.1", "8.0", "8.1", "8.2", "8.3", "9.0", "9.1", "9.2", "9.3", "10.0", "10.1", "10.2", "10.3","11.0", "11.1", "11.2", "11.3", "11.4", "12.0", "12.1", "12.2", "12.3", "12.4","13.0", "13.1", "13.2", "13.3", "13.4", "13.5", "13.6", "13.7","14.0", "14.1", "14.2", "14.3", "14.4", "14.5", "14.6", "14.7", "14.8","15.0", "15.1", "15.2", "15.3", "15.4", "15.5", "15.6", "16.0", "16.1","16.2", "16.3", "16.4", "16.5", "16.6", "17.0", "17.1"]sdk: ["iphoneos", "iphonesimulator"]sdk_version: [null, "11.3", "11.4", "12.0", "12.1", "12.2", "12.4","13.0", "13.1", "13.2", "13.4", "13.5", "13.6", "13.7","14.0", "14.1", "14.2", "14.3", "14.4", "14.5", "15.0", "15.2", "15.4","15.5", "16.0", "16.1", "16.2", "16.4", "17.0", "17.1"]watchOS:version: ["4.0", "4.1", "4.2", "4.3", "5.0", "5.1", "5.2", "5.3", "6.0", "6.1", "6.2","7.0", "7.1", "7.2", "7.3", "7.4", "7.5", "7.6", "8.0", "8.1", "8.3", "8.4","8.5", "8.6", "8.7", "9.0", "9.1", "9.2", "9.3", "9.4", "9.5", "9.6","10.0", "10.1"]sdk: ["watchos", "watchsimulator"]sdk_version: [null, "4.3", "5.0", "5.1", "5.2", "5.3", "6.0", "6.1", "6.2","7.0", "7.1", "7.2", "7.4", "8.0", "8.0.1", "8.3", "8.5", "9.0", "9.1","9.4", "10.0", "10.1"]tvOS:version: ["11.0", "11.1", "11.2", "11.3", "11.4", "12.0", "12.1", "12.2", "12.3", "12.4","13.0", "13.2", "13.3", "13.4", "14.0", "14.2", "14.3", "14.4", "14.5","14.6", "14.7", "15.0", "15.1", "15.2", "15.3", "15.4", "15.5", "15.6","16.0", "16.1", "16.2", "16.3", "16.4", "16.5", "16.6", "17.0", "17.1"]sdk: ["appletvos", "appletvsimulator"]sdk_version: [null, "11.3", "11.4", "12.0", "12.1", "12.2", "12.4","13.0", "13.1", "13.2", "13.4", "14.0", "14.2", "14.3", "14.5", "15.0","15.2", "15.4", "16.0", "16.1", "16.4", "17.0", "17.1"]visionOS:version: ["1.0"]sdk: ["xros", "xrsimulator"]sdk_version: [null, "1.0"]Macos:version: [null, "10.6", "10.7", "10.8", "10.9", "10.10", "10.11", "10.12", "10.13", "10.14", "10.15","11.0", "11.1", "11.2", "11.3", "11.4", "11.5", "11.6", "11.7","12.0", "12.1", "12.2", "12.3", "12.4", "12.5", "12.6", "12.7","13.0", "13.1", "13.2", "13.3", "13.4", "13.5", "13.6","14.0", "14.1", "14.2", "14.3", "14.4"]sdk_version: [null, "10.13", "10.14", "10.15", "11.0", "11.1", "11.3", "12.0", "12.1","12.3", "13.0", "13.1", "13.3", "14.0"]subsystem:null:catalyst:ios_version: *ios_versionAndroid:api_level: [ANY]FreeBSD:SunOS:AIX:Arduino:board: [ANY]Emscripten:Neutrino:version: ["6.4", "6.5", "6.6", "7.0", "7.1"]baremetal:VxWorks:version: ["7"]
arch: [x86, x86_64, ppc32be, ppc32, ppc64le, ppc64,armv4, armv4i, armv5el, armv5hf, armv6, armv7, armv7hf, armv7s, armv7k, armv8, armv8_32, armv8.3, arm64ec,sparc, sparcv9,mips, mips64, avr, s390, s390x, asm.js, wasm, sh4le,e2k-v2, e2k-v3, e2k-v4, e2k-v5, e2k-v6, e2k-v7,riscv64, riscv32,xtensalx6, xtensalx106, xtensalx7]
compiler:sun-cc:version: ["5.10", "5.11", "5.12", "5.13", "5.14", "5.15"]threads: [null, posix]libcxx: [libCstd, libstdcxx, libstlport, libstdc++]gcc:version: ["4.1", "4.4", "4.5", "4.6", "4.7", "4.8", "4.9","5", "5.1", "5.2", "5.3", "5.4", "5.5","6", "6.1", "6.2", "6.3", "6.4", "6.5","7", "7.1", "7.2", "7.3", "7.4", "7.5","8", "8.1", "8.2", "8.3", "8.4", "8.5","9", "9.1", "9.2", "9.3", "9.4", "9.5","10", "10.1", "10.2", "10.3", "10.4", "10.5","11", "11.1", "11.2", "11.3", "11.4","12", "12.1", "12.2", "12.3","13", "13.1", "13.2"]libcxx: [libstdc++, libstdc++11]threads: [null, posix, win32]  # Windows MinGWexception: [null, dwarf2, sjlj, seh]  # Windows MinGWcppstd: [null, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23]msvc:version: [170, 180, 190, 191, 192, 193]update: [null, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]runtime: [static, dynamic]runtime_type: [Debug, Release]cppstd: [null, 14, 17, 20, 23]toolset: [null, v110_xp, v120_xp, v140_xp, v141_xp]clang:version: ["3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "4.0","5.0", "6.0", "7.0", "7.1","8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18"]libcxx: [null, libstdc++, libstdc++11, libc++, c++_shared, c++_static]cppstd: [null, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23]runtime: [null, static, dynamic]runtime_type: [null, Debug, Release]runtime_version: [null, v140, v141, v142, v143]apple-clang:version: ["5.0", "5.1", "6.0", "6.1", "7.0", "7.3", "8.0", "8.1", "9.0", "9.1","10.0", "11.0", "12.0", "13", "13.0", "13.1", "14", "14.0", "15", "15.0"]libcxx: [libstdc++, libc++]cppstd: [null, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23]intel-cc:version: ["2021.1", "2021.2", "2021.3", "2021.4", "2022.1", "2022.2","2022.3", "2023.0", "2023.1", "2023.2", "2024.0",]update: [null, ANY]mode: ["icx", "classic", "dpcpp"]libcxx: [null, libstdc++, libstdc++11, libc++]cppstd: [null, 98, gnu98, "03", gnu03, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23]runtime: [null, static, dynamic]runtime_type: [null, Debug, Release]qcc:version: ["4.4", "5.4", "8.3"]libcxx: [cxx, gpp, cpp, cpp-ne, accp, acpp-ne, ecpp, ecpp-ne]cppstd: [null, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17]mcst-lcc:version: ["1.19", "1.20", "1.21", "1.22", "1.23", "1.24", "1.25"]libcxx: [libstdc++, libstdc++11]cppstd: [null, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23]build_type: [null, Debug, Release, RelWithDebInfo, MinSizeRel]

关注我,学习更多C/C++,算法,计算机知识

B站:

👨‍💻主页:天赐细莲 bilibili

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

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

相关文章

国产操作系统下Chrome的命令行使用 _ 统信 _ 麒麟

原文链接&#xff1a;国产操作系统下Chrome的命令行使用 | 统信 | 麒麟 Hello&#xff0c;大家好啊&#xff01;今天我们来聊聊如何在国产操作系统上使用命令行操作Google Chrome。无论是进行自动化测试、网页截图还是网页数据抓取&#xff0c;使用命令行操作Google Chrome都能…

Go编程语言的调试器Delve | Goland远程连接Linux开发调试(go远程开发)

文章目录 Go编程语言的调试器一、什么是Delve二、delve 安装安装报错cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH解决 三、delve命令行使用delve 常见的调试模式常用调试方法todo调试程序代码与动态库加载程序运行…

常用的简单友好的工单系统(免费)- WGCAT

最近在项目中&#xff0c;有工单系统的需求场景&#xff0c;所以想寻找一款轻量简单的运维工单软件&#xff0c;主要用来记录和处理工作中的一些故障、维护&#xff0c;主要用来记录设备的维护状态&#xff0c;包括服务器、主机、交换机那些 WGCAT&#xff0c;是一款简单轻量的…

知从科技战略客户经理张志强受邀出席2024 AutoSec中国汽车网络安全与数据安全峰会

4月11-12日&#xff0c;AutoSec8周年年会暨中国汽车网络安全及数据安全合规峰会在上海成功举办。此次峰会吸引了来自全球各地的头部汽车网络安全企业、OEM厂商、安全专家和学者等齐聚盛会&#xff0c;零距离共话智能网联汽车产业的新发展、新趋势。 知从科技董事长成云霞亲自带…

mapreduce | 自定义Partition分区(案例1)

1.需求 将学生成绩&#xff0c;按照各个成绩降序排序&#xff0c;各个科目成绩单独输出。 # 自定义partition 将下面数据分区处理&#xff1a; 人名 科目 成绩 张三 语文 10 李四 数学 30 王五 语文 20 赵6 英语 40 张三 数据 50 李四 语文 10 张三 英语 70 李四 英语…

MapReduce | 二次排序

1.需求 主播数据--按照观众人数降序排序&#xff0c;如果观众人数相同&#xff0c;按照直播时长降序 # 案例数据 用户id 观众人数 直播时长 团团 300 1000 小黑 200 2000 哦吼 400 7000 卢本伟 100 6000 八戒 250 5000 悟空 100 4000 唐僧 100 3000 # 期望结果 哦吼 4…

字典是如何实现的?Rehash 了解吗?

字典是 Redis 服务器中出现最为频繁的复合型数据结构。除了 hash 结构的数据会用到字典外&#xff0c;整个 Redis 数据库的所有 key 和 value 也组成了一个 全局字典&#xff0c;还有带过期时间的 key 也是一个字典。(存储在 RedisDb 数据结构中) 字典结构是什么样的呢&#xf…

vue3 自定义国际化、elementPlus 国际化

自定义国际化 1. 引入 vue-i18n 插件 pnpm install vue-i18nnext 2. 页面添加语言文件目录&#xff0c;添加自定义的语言文件 3.语言目录里添加 index.ts&#xff0c; 内容如下 import { createI18n } from "vue-i18n";// 自定义语言文件 import zhCN from "…

【C/C++】内存分布

本文第一部分主要介绍了程序内存区域的划分以及数据的存储。第二部分有一段代码和一些题目&#xff0c;全面直观得分析了程序中的数组在内存中的存储。 因为不同的数据有不同的存储需求&#xff0c;各区域满足不同的需求&#xff0c;所以程序内存会有区域的划分。 根据需求的不…

MFC重要的初始化函数InitInstance

MFC应用程序最早处理的类的初始化函数通常是CWinApp类的构造函数。CWinApp类是MFC应用程序的主类&#xff0c;负责整个应用程序的初始化和管理。 在MFC应用程序中&#xff0c;通常会创建一个派生自CWinApp类的应用程序类&#xff0c;例如CMyApp。在应用程序启动时&#xff0c;…

【数据结构(邓俊辉)学习笔记】二叉树01——二叉树表示与实现

文章目录 0.概述1.树1.1 应用1.2 有根树1.3 有序树1.4 路径环路1.5 深度 层。1.6 树的表示 2. 二叉树的概述3 二叉树实现3.1 二叉树节点3.2 二叉树节点操作接口3.3 二叉树的实现 0.概述 介绍下二叉树的表示与实现。 1.树 1.1 应用 后缀表达式。 相对于线性结构O&#xff08…

力扣HOT100 - 121. 买卖股票的最佳时机

解题思路&#xff1a; 每次遍历price&#xff0c;更新最小的cost和最大的profit class Solution {public int maxProfit(int[] prices) {int cost Integer.MAX_VALUE, profit 0;for (int price : prices) {cost Math.min(cost, price);profit Math.max(profit, price - c…

MFC的句柄概念以及句柄类型

在MFC&#xff08;Microsoft Foundation Class&#xff09;桌面应用程序中&#xff0c;窗口是通过句柄&#xff08;Handle&#xff09;来进行管理和操作的。 句柄是一个标识符&#xff0c;用于唯一标识和引用窗口、控件、设备上下文等对象。在MFC桌面应用程序中&#xff0c;常…

LeetCode100题总结

LeetCode100题总结 前言LeetCode100题总结题型梳理双指针11. 盛最多水的容器234.回文链表75.颜色分类206.反转链表142.环形链表215.三数之和 滑动窗口3. 无重复字符的最长子串209. 长度最小的子数组438. 找到字符串中所有字母异位词 广搜102. 二叉树的层序遍历200. 岛屿数量617…

一对一WebRTC视频通话系列(六)——部署到公网

本系列博客主要记录一对一WebRTC视频通话实现过程中的一些重点&#xff0c;代码全部进行了注释&#xff0c;便于理解WebRTC整体实现。 本专栏知识点是通过<零声教育>的音视频流媒体高级开发课程进行系统学习&#xff0c;梳理总结后写下文章&#xff0c;对音视频相关内容感…

leetcode--560和为k的子数组

问题 给你一个整数数组 nums 和一个整数 k &#xff0c;请你统计并返回 该数组中和为 k 的子数组的个数 。 子数组是数组中元素的连续非空序列。 示例 1&#xff1a; 输入&#xff1a;nums [1,1,1], k 2 输出&#xff1a;2示例 2&#xff1a; 输入&#xff1a;nums [1,2…

数据分析需要注意哪些法律法规

数据分析 前言一、数据处理过程二、数据收集阶段的法律规则数据收集应具备合法、正当、透明原则数据收集应坚持最小必要原则数据收集应遵守知情-同意规则数据收集应遵守目的明确性要求 三、数据储存的法律规则四、数据使用与处理的阶段的法律规则数据安全保护义务按照数据分级分…

【荣耀笔试题汇总】2024-05-11-荣耀春招笔试题-三语言题解(CPP/Python/Java)

&#x1f36d; 大家好这里是清隆学长 &#xff0c;一枚热爱算法的程序员 ✨ 本系列打算持续跟新小米近期的春秋招笔试题汇总&#xff5e; &#x1f4bb; ACM银牌&#x1f948;| 多次AK大厂笔试 &#xff5c; 编程一对一辅导 &#x1f44f; 感谢大家的订阅➕ 和 喜欢&#x1f49…

【漏洞复现】泛微OA E-Cology portalTsLogin文件读取漏洞

漏洞描述&#xff1a; 泛微E-Cology是一款面向中大型组织的数字化办公产品&#xff0c;它基于全新的设计理念和管理思想&#xff0c;旨在为中大型组织创建一个全新的高效协同办公环境。泛微OA E-Cology portalTsLogin存在任意文件读取漏洞&#xff0c;允许未经授权的用户读取服…

了解当前经济,VBA一键获取不同货币实时汇率

了解当前经济数据,VBA一键获取不同货币间实时汇率 当下较火的经济新闻:黄金价格、日元贬值、美元加息等,咱们不去分析了解这些经济变动背后的动机及原因,做一点本份的事,如何用VBA获取不同货币之间的实时汇率。这肯定是需要联网的,现从“外汇查询” 网站(https://www.wa…