c++包管理工具conan使用

Posted qusir

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c++包管理工具conan使用相关的知识,希望对你有一定的参考价值。

安装

sudo pip install conan

参考官网的demo

git clone https://github.com/memsharded/example-poco-timer.git mytimer

命令

查看本地库
conan search 
安装库
conan install zlib/[email protected]/stable
删除库
conan remove zlib/[email protected]/stable

编写conanfile.txt文件

[requires]
Poco/[email protected]/stable


[generators]
gcc

编写main.cpp源文件

// $Id: //poco/1.4/Foundation/samples/Timer/src/Timer.cpp#1 $
// This sample demonstrates the Timer and Stopwatch classes.
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
// SPDX-License-Identifier:     BSL-1.0

#include "Poco/Timer.h"
#include "Poco/Thread.h"
#include "Poco/Stopwatch.h"
#include <iostream>

using Poco::Timer;
using Poco::TimerCallback;
using Poco::Thread;
using Poco::Stopwatch;

class TimerExample{
public:
        TimerExample(){ _sw.start();}

        void onTimer(Timer& timer){
                std::cout << "Callback called after " << _sw.elapsed()/1000 << " milliseconds." << std::endl;
        }
private:
        Stopwatch _sw;
};

int main(int argc, char** argv){
        TimerExample example;
        Timer timer(250, 500);
        timer.start(TimerCallback<TimerExample>(example, &TimerExample::onTimer));

        Thread::sleep(5000);
        timer.stop();
        return 0;
}

根据conanfile.txt文件生成conanbuildinfo.gcc conanbuildinfo.txt conaninfo.txt文件

conan install .

使用conanbuildinfo.gcc文件

gcc main.cpp -o main -DBOOST_USE_STATIC_LIBS -DPOCO_STATIC=ON -DPOCO_NO_AUTOMATIC_LIBS -I/home/qusir/.conan/data/Poco/1.8.0.1/pocoproject/stable/package/8a67b44a092c0074e3cb946a9ddada338054b11e/include -I/home/qusir/.conan/data/boost/1.66.0/conan/stable/package/eacfdb5f448bfd89f0b2950fb6b7a79e44c7ea08/include -I/home/qusir/.conan/data/OpenSSL/1.0.2l/conan/stable/package/0abbb2ea17cdc92f4a2ac8a9e55de717e3b5a9d1/include -I/home/qusir/.conan/data/bzip2/1.0.6/conan/stable/package/76f87539fc90ff313e0b3182641a9bb558a717d2/include -I/home/qusir/.conan/data/zlib/1.2.11/conan/stable/package/d358fec34c04bcd89832a09158783c750a3304dc/include -m64 -s -DNDEBUG -Wl,-rpath="/home/qusir/.conan/data/Poco/1.8.0.1/pocoproject/stable/package/8a67b44a092c0074e3cb946a9ddada338054b11e/lib" -Wl,-rpath="/home/qusir/.conan/data/boost/1.66.0/conan/stable/package/eacfdb5f448bfd89f0b2950fb6b7a79e44c7ea08/lib" -Wl,-rpath="/home/qusir/.conan/data/OpenSSL/1.0.2l/conan/stable/package/0abbb2ea17cdc92f4a2ac8a9e55de717e3b5a9d1/lib" -Wl,-rpath="/home/qusir/.conan/data/bzip2/1.0.6/conan/stable/package/76f87539fc90ff313e0b3182641a9bb558a717d2/lib" -Wl,-rpath="/home/qusir/.conan/data/zlib/1.2.11/conan/stable/package/d358fec34c04bcd89832a09158783c750a3304dc/lib" -L/home/qusir/.conan/data/Poco/1.8.0.1/pocoproject/stable/package/8a67b44a092c0074e3cb946a9ddada338054b11e/lib -L/home/qusir/.conan/data/boost/1.66.0/conan/stable/package/eacfdb5f448bfd89f0b2950fb6b7a79e44c7ea08/lib -L/home/qusir/.conan/data/OpenSSL/1.0.2l/conan/stable/package/0abbb2ea17cdc92f4a2ac8a9e55de717e3b5a9d1/lib -L/home/qusir/.conan/data/bzip2/1.0.6/conan/stable/package/76f87539fc90ff313e0b3182641a9bb558a717d2/lib -L/home/qusir/.conan/data/zlib/1.2.11/conan/stable/package/d358fec34c04bcd89832a09158783c750a3304dc/lib -lPocoUtil -lPocoMongoDB -lPocoNet -lPocoNetSSL -lPocoCrypto -lPocoData -lPocoDataSQLite -lPocoZip -lPocoXML -lPocoJSON -lPocoFoundation -lpthread -lrt -lboost_wave -lboost_container -lboost_exception -lboost_graph -lboost_iostreams -lboost_locale -lboost_log -lboost_program_options -lboost_random -lboost_regex -lboost_wserialization -lboost_serialization -lboost_signals -lboost_coroutine -lboost_context -lboost_timer -lboost_thread -lboost_chrono -lboost_date_time -lboost_atomic -lboost_filesystem -lboost_system -lboost_type_erasure -lboost_log_setup -lboost_stacktrace_backtrace -lboost_math_tr1l -lboost_math_tr1f -lboost_stacktrace_basic -lboost_stacktrace_addr2line -lboost_math_c99f -lboost_math_tr1 -lboost_stacktrace_noop -lboost_math_c99l -lboost_math_c99 -lboost_unit_test_framework -lssl -lcrypto -ldl -lbz2 -lz -D_GLIBCXX_USE_CXX11_ABI=0 -lstdc++

其实就是将conanbuildinfo.gcc内容添加到gcc编译选项中

查找远程库

conan remote add conan-transit https://conan-transit.bintray.com
conan search --remote conan-transit

conan remote add conan-center https://conan.bintray.com
conan search --remote conan-center

以上是关于c++包管理工具conan使用的主要内容,如果未能解决你的问题,请参考以下文章

C/C++ 如何进行持续交付 ?使用 Jenkins+Conan!

conan入门(二十六):使用make编译erpc/erpcgen(makefile)

conan入门(二十六):使用make编译erpc/erpcgen(makefile)

CMake 入门学习4 软件包管理

CMake 入门学习4 软件包管理

conan入门:将自己的项目生成conan包