Conan C/C++ 包管理软件笔记
简介
Conan 作为 C++ 包管理软件,类似JAVA中的maven,Python中的pip ,Node中的npm。
生命周期
conan-cheatsheet_看图王.jpg远程仓库地址
JFrog ConanCenter - The Central Repository for C / C++ packages
conanfile.txt
[requires]
nlohmann_json/3.10.2
libcurl/7.64.1
boost/1.77.0
[generators]
cmake
[build_requires]
openssl/1.1.1l
[options]
*:shared=True
[imports]
bin, *.dll -> ./bin
bin, *.dylib* -> ./lib
lib, *.so* -> ./bin
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(demo4)
#设置C++版本
set(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
#关闭编译器检查
set(CONAN_DISABLE_CHECK_COMPILER ON)
#设置编译后执行文件路径
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
#设置编译后库文件路径
#set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
#加载conan文件
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
#生成执行文件
add_executable(demo4 main.cpp)
#CONAN_LIBS 绑定库信息
target_link_libraries(demo4 ${CONAN_LIBS})
linux.profiles
[settings]
os=Linux
arch=x86_64
build_type=Release
compiler=gcc
compiler.version=8
compiler.libcxx=libstdc++11
[env]
CC=/usr/local/gcc/8.1.0/bin/gcc
CXX=/usr/local/gcc/8.1.0/bin/g++
window.profiles
[settings]
os=Windows
arch=x86_64
compiler=Visual Studio
compiler.version=16
build_type=Release
[options]
[tool_requires]
[env]
conan和CMAKE命令
#编译依赖库,并且生产cmake文件
conan install .. --build
#指定编译环境,且编译依赖库,并且生产cmake文件
conan install .. --build --profile ../linux.profiles
#指定编译器
conan install .. --build -s compiler.version=8
#编译boost,bzip2依赖库,并且生产cmake文件
conan install .. --build=boost,bzip2
#编译debug或release版本
conan install . -s build_type=Debug --install-folder=cmake-build-debug
conan install . -s build_type=Release --install-folder=cmake-build-release
#从仓库下载二进制库,-g deploy 将二进制库复制到编译目录,用于开发, --profile ../linux.profiles 设置编辑环境 --build missing 不本地编译
conan install .. -s compiler.version=8 -g deploy --profile ../linux.profiles --build missing
#生产二进制库的依赖关系
conan info .. --graph=file.html
#获取环境
conan profile list
#查看默认环境
conan profile show default
#打包到本地仓库
conan test_package -pr=default
#获取boost/1.74.0信息
conan get boost/1.74.0
#获取远程仓库信息
conan remote list --raw
#新增远程仓库信息
conan remote add conan-center https://center.conan.io False
#更新远程仓库信息
conan remote update conan-center https://center.conan.io False
#删除远程仓库
conan remote remove conan-center
#添加加载库信息
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/data/demo4/cmake-build-debug-centos/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/demo4/cmake-build-debug-centos/lib
#cmake编译名称
(win)
cmake .. -G "Visual Studio 16"
cmake --build . --config Release
(linux, mac)
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
cmake --build .
#打印详细编译信息,方面查找问题
make VERBOSE=1
#编译两种方式
compiler.libcxx=
libstdc++
libstdc++11
docker编译器环境
#开启目录权限
chmod a+rwx /data/demo4/
#使用docker容器编译代码
--rm 表示退出容器清除内容
docker run -it -p 10022:22 --privileged=true -v /data/demo4:/home/conan/demo4 -v /data/.conan:/home/conan/.conan/ --rm conanio/gcc8:1.40.2 /bin/bash
docker run -it -p 10022:22 --privileged=true -v /data/demo4:/home/conan/demo4 --rm conanio/gcc48:latest /bin/bash
网友评论