conan2 基础入门(03)-使用(msvc为例)
文章目录
⭐准备
在阅读和学习本文前,希望有一定的cmake基础。
cmake基础:
Build a simple CMake project using Conan — conan 2.3.0 documentation
在conan官网中有简单的示例教程。
生成profile
文件
在使用conan前,需要先准备一个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
在笔者测试机(装有vs2019)上会出现如下显示。其实就是一个.ini
格式的配置文件(但并非完全的ini,conan有自己的特殊处理)。
detect_api: Found msvc 16
Detected profile:
[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=14
compiler.runtime=dynamic
compiler.version=192
os=Windows
WARN: 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\lotus\.conan2\profiles\default
C:.
│ global.conf
│ settings.yml
│ version.txt
│
├─extensions
│ └─plugins
│ │ profile.py
│ │
│ └─compatibility
│ compatibility.py
│ cppstd_compat.py
│
└─profiles
default
预备文件和Code
文件名预览
:.
│ CMakeLists.txt
│ conanfile.txt
└─ main.cpp
main.cpp
#include <iostream>
#include "zlib.h"
void test_env() {
std::cout << ">>>" << __fun