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

news2024/11/16 17:39:55

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=mygcc

cd build

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

cmake --build . --config Release

cd ../bin

mydemo.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 home

C:\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_version
    Android:
        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 MinGW
        exception: [null, dwarf2, sjlj, seh]  # Windows MinGW
        cppstd: [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.coloradmin.cn/o/1665544.html

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

相关文章

深入理解Linux下的网络监控工具:iftop

目录标题 1. 什么是iftop?2. 安装iftop在Debian/Ubuntu上安装在CentOS/RHEL上安装在其他Linux发行版上 3. 使用iftop监控网络流量命令行选项界面说明交互命令 4. 相关参数及说明 在维护和监控Linux服务器时&#xff0c;了解网络流量的细节非常重要。网络监控可以帮助我们诊断延…

面向电商家居行业3D室内场景合成中的空间感知

本文主要介绍了3D场景合成技术在电商领域&#xff0c;尤其是家居家装行业的应用。它解释了如何使用3D场景合成创建逼真的室内设计&#xff0c;让消费者能够交互式地查看和体验产品&#xff0c;提高购物的趣味性和效率。文章提到了两种主要的3D室内场景生成算法&#xff1a;传统…

软考-软件工程

软件工程概述 软件工程指的是应用计算机科学、数学及管理科学等原理&#xff0c;以工程化的原则和方法来解决软件 问题的工程&#xff0c;目的是提高软件生产率、提高软件质量、降低软件成本。 概述&#xff1a; 软件开发模型&#xff1a;指导软件开发的体系 需求分析确定软件…

力扣127.单词接龙讲解

距离上一次刷题已经过去了.........嗯............我数一一下............整整十天&#xff0c;今天再来解一道算法题 由于这段时间准备简历&#xff0c;没咋写博客。。今天回来了&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&…

ctfshow SSRF 351-358

做题前,需要先学习关于ssrf漏洞的相关知识 小注意: 当使用 file_get_contents() 函数访问远程 URL 时&#xff0c;它会尝试获取该 URL 指向的资源的内容&#xff0c;并将内容以字符串的形式返回。 如果 b.php 文件是一个 PHP 文件&#xff0c;它包含的内容取决于该 PHP 文件…

Visual Studio,第1个hello world,入门C++,分别编译一个可以在Windows和Linux下运行的程序

本人的VxTerm&#xff0c;是在Visual Studio 2022下编写的。 其它的语言工具是不是也可以那么方便的使用&#xff0c;本人并不得而知&#xff0c;至少本人能知道&#xff1a;对于我来说&#xff0c;Visual Studio可以让我觉得C/C语言非常简单&#xff01; 一、安装Visual Stu…

D - Another Sigma Problem(ABC)

思路&#xff1a;我们可以处理一个后缀来记录当前数a[i]需要乘上多少&#xff08;类似于1110这样的&#xff09;&#xff0c;然后对于当前位来说&#xff0c;对答案的贡献还要加上(i - 1) * a[i]&#xff0c;因为a[i]还要做前(i - 1)个数的后缀。 代码&#xff1a; #include &…

基于FPGA的NC图像质量评估verilog实现,包含testbench和MATLAB辅助验证程序

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 5.算法完整程序工程 1.算法运行效果图预览 vivado2019.2和matlab2022a测试&#xff0c;结果如下&#xff1a; 2.算法运行软件版本 vivado2019.2 matlab2022a 3.部分核心程序 timescale …

数据中台:企业数字化转型的桥梁_光点科技

在数字化日益深入企业核心运营的今天&#xff0c;数据中台作为一个关键的信息化架构&#xff0c;正逐渐崭露头角&#xff0c;成为连接企业各部门、优化数据管理和推动业务创新的重要桥梁。 一、数据中台&#xff1a;连接与整合的桥梁 数据中台的核心作用在于连接与整合。传统的…

深入理解MySQL三大日志:redo log、binlog、undo log

前言 MySQL是一个功能强大的关系型数据库管理系统&#xff0c;它的高可靠性、高性能和易用性使得它成为众多企业和开发者的首选。在MySQL内部&#xff0c;为了保证数据的完整性、恢复能力和并发性能&#xff0c;设计了一套复杂的日志系统。其中&#xff0c;redo log、bin log和…

Android 13 系统自定义安全水印

效果 源码实现 frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java public final void showSafeModeOverlay() {View v LayoutInflater.from(mContext).inflate(com.android.internal.R.layout.safe_mode, null);WindowManager.Layout…

串口数据的发送(单词的发送)and UART原理协议---第九天

1.在中断函数中&#xff0c;定义一个数组给SBUF&#xff0c; i数组的偏移以便输入单词&#xff0c;&#xff1b; 用strstr&#xff08;&#xff09;函数来比较cmd输入的单词里面的 "en" , " se ";亮灯后i回来原来的位置0&#xff0c;清空cmd, UART 原理…

搭建私有仓库Nexus的流程以及npm包的开发和发布

搭建私有仓库 Nexus 的流程&#xff08;Ubuntu&#xff09;以及 npm 包的开发和发布 本文档是关于在 Ubuntu 上面搭建 Nexus&#xff0c;以及制作 npm 包并发布到 Nexus 的流程说明。 关于 Ubuntu Ubuntu 是一个基于 Linux 的操作系统&#xff0c;通常会用在服务器或者嵌入式…

Git团队协作机制

Git 团队协作机制 1.团队内协作 小故事&#xff1a;岳不群手里有华山剑法但是不完整&#xff0c;需要弟子令狐冲进行完善&#xff0c;岳不群将华山剑法推送&#xff08;push&#xff09;到代码托管中心&#xff0c;这样岳不群就有属于自己的远程库&#xff0c;令狐冲从远程库…

(文章复现)基于变异粒子群算法的主动配电网故障恢复策略

参考文献&#xff1a; [1]徐岩,张荟,孙易洲.基于变异粒子群算法的主动配电网故障恢复策略[J].电力自动化设备,2021,41(12):45-53.DOI:10.16081/j.epae.202108030. 1.基本原理 为提高主动配电网故障恢复的快速性和可靠性&#xff0c;提出一种基于变异粒子群算法的恢复策略。光…

六级翻译笔记

理解加表达 除了专有名词不能自己理解翻译&#xff0c;其它都可以 时态一般唯一 题目里出现有翻译为 客观存在&#xff1a; there be 单词结尾加er和ee的区别&#xff1a;er是主动&#xff0c;ee是被动 中文句子没有被动&#xff0c;也可以英文翻译为被动 中文的状语可以不是…

3月笔记本电脑行业线上市场销售数据分析

笔记本电脑市场在过去几年中经历了起伏&#xff0c;但总体上呈现出稳定增长的态势。特别是随着远程办公、在线学习等需求的增加&#xff0c;以及消费者对于便携性、高性能等方面的追求&#xff0c;笔记本电脑市场得到了进一步的发展。 据鲸参谋数据统计&#xff0c;线上平台&a…

在Tiled中制作动画瓦片图

什么是瓦片图&#xff1f;瓦片图是指用图块把游戏场景评出来 工具安装链接&#xff1a;Tiled | Flexible level editor 资源下载教程 资源下载&#xff1a;Mystic Woods - 16x16 Pixel Art Asset Pack by Game Endeavor 解压后得到一些资源 新建图块集合 Tiled的安装就不介绍…

2024最新从0部署Django项目(nginx+uwsgi+mysql)

云服务器 我这里用的是腾讯云免费试用的2H4Gcentos服务器&#xff08;后升级为2H8G&#xff0c;保险一点提高内存&#xff09; 因为网上很多关于django部属的教程都是宝塔啊&#xff0c;python版本控制器啊这种的&#xff0c;我也误打误撞安装了宝塔面板&#xff0c;但这里我…

AR人像滤镜SDK解决方案,专业调色,打造个性化风格

视觉内容已成为企业传达品牌价值和吸引用户眼球的重要载体&#xff0c;为满足企业对于高质量、多样化视觉内容的迫切需求&#xff0c;美摄科技凭借先进的AR技术和深厚的图像处理经验&#xff0c;推出了业界领先的AR人像滤镜SDK解决方案。 一、一站式解决方案&#xff0c;覆盖多…