首页 > 编程语言 >c++ boost库安装与测试

c++ boost库安装与测试

时间:2023-10-01 23:44:09浏览次数:31  
标签:11 16 -- boost c++ 测试 root Oct libboost

1、从官网http://www.boost.org/users/download/下载最新版本的boost,如boost_1_65_0

2、解压tar xzvf boost_1_65_0.tar.gz,

3、安装

cd boost_1_65_0/

./bootstrap.sh
sudo ./b2 install
 4、测试boost,以any类型和uuid为例。
#include <iostream>
#include <list>
#include <vector>
#include <boost/any.hpp>
#include <sys/time.h>

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <uuid/uuid.h>

#include "test_stl.h"

using namespace std;
typedef std::list<boost::any> list_any;

//关键部分:可以存放任意类型的对象
void fill_list(list_any& la)
{
    la.push_back(10);//存放常数
    la.push_back( std::string("dyunze") );//存放字符串对象;注意la.push_back(“dyunze”)错误,因为会被当错字符串数组
}

//根据类型进行显示
void show_list(list_any& la)
{
    list_any::iterator it;
    boost::any anyone;

    for( it = la.begin(); it != la.end(); it++ )
    {
        anyone = *it;

        if( anyone.type() == typeid(int) )
            std::cout<<boost::any_cast<int>(*it)<<std::endl;
        else if( anyone.type() == typeid(std::string) )
            std::cout<<boost::any_cast<std::string>(*it).c_str()<<std::endl;
    }
}

// boost版本异常慢
void test_uuid_perf()
{
    // boost::uuids::uuid a_uuid;
    vector<string> myvertor;
    uuid_t uu;
    char uuid_str[37];
    
    struct timeval start, stop, diff;
    gettimeofday(&start, 0);   //开始计时
    for (int i=0;i<100000;i++)
    {
        // a_uuid = boost::uuids::random_generator()();
        // myvertor.emplace_back(boost::uuids::to_string(a_uuid));
        uuid_generate(uu);
    
        uuid_unparse_lower(uu, uuid_str);
        string str1(uuid_str);
        myvertor.emplace_back(str1);

    }
    cout << myvertor[10] << endl;
    gettimeofday(&stop, 0);   //结束计时
    timeval_subtract(&diff, &start, &stop);
    printf("总计用时:%d秒%d微秒\n",diff.tv_sec, diff.tv_usec);  // boost版本,10万个uuid 17秒多; uuid版本, 10万个0.5秒,35倍
    printf("完成");
}

int test_boost()
{
    list_any la;
    fill_list(la);
    show_list(la);

    test_uuid_perf();
    return 0;
}

注:boost本身大部分工具库为header-only库,一小部分专用的需要链接。从下也可知:

[zjh@hs-10-20-30-193 cpp_demo]$ cd /usr/local/lib
[zjh@hs-10-20-30-193 lib]$ ll | grep boost
-rw-r--r-- 1 root root 2602 Oct 1 16:11 libboost_atomic.a
lrwxrwxrwx 1 root root 25 Oct 1 16:11 libboost_atomic.so -> libboost_atomic.so.1.65.0
-rwxr-xr-x 1 root root 8392 Oct 1 16:11 libboost_atomic.so.1.65.0
-rw-r--r-- 1 root root 110550 Oct 1 16:11 libboost_chrono.a
lrwxrwxrwx 1 root root 25 Oct 1 16:11 libboost_chrono.so -> libboost_chrono.so.1.65.0
-rwxr-xr-x 1 root root 36432 Oct 1 16:11 libboost_chrono.so.1.65.0
-rw-r--r-- 1 root root 166074 Oct 1 16:11 libboost_container.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_container.so -> libboost_container.so.1.65.0
-rwxr-xr-x 1 root root 118224 Oct 1 16:11 libboost_container.so.1.65.0
-rw-r--r-- 1 root root 74878 Oct 1 16:11 libboost_context.a
lrwxrwxrwx 1 root root 26 Oct 1 16:11 libboost_context.so -> libboost_context.so.1.65.0
-rwxr-xr-x 1 root root 55336 Oct 1 16:11 libboost_context.so.1.65.0
-rw-r--r-- 1 root root 97300 Oct 1 16:11 libboost_coroutine.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_coroutine.so -> libboost_coroutine.so.1.65.0
-rwxr-xr-x 1 root root 62192 Oct 1 16:11 libboost_coroutine.so.1.65.0
-rw-r--r-- 1 root root 148634 Oct 1 16:11 libboost_date_time.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_date_time.so -> libboost_date_time.so.1.65.0
-rwxr-xr-x 1 root root 94416 Oct 1 16:11 libboost_date_time.so.1.65.0
-rw-r--r-- 1 root root 1662 Oct 1 16:11 libboost_exception.a
-rw-r--r-- 1 root root 245588 Oct 1 16:11 libboost_filesystem.a
lrwxrwxrwx 1 root root 29 Oct 1 16:11 libboost_filesystem.so -> libboost_filesystem.so.1.65.0
-rwxr-xr-x 1 root root 127128 Oct 1 16:11 libboost_filesystem.so.1.65.0
-rw-r--r-- 1 root root 773386 Oct 1 16:11 libboost_graph.a
lrwxrwxrwx 1 root root 24 Oct 1 16:11 libboost_graph.so -> libboost_graph.so.1.65.0
-rwxr-xr-x 1 root root 450264 Oct 1 16:11 libboost_graph.so.1.65.0
-rw-r--r-- 1 root root 340650 Oct 1 16:11 libboost_iostreams.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_iostreams.so -> libboost_iostreams.so.1.65.0
-rwxr-xr-x 1 root root 152304 Oct 1 16:11 libboost_iostreams.so.1.65.0
-rw-r--r-- 1 root root 2899498 Oct 1 16:11 libboost_locale.a
lrwxrwxrwx 1 root root 25 Oct 1 16:11 libboost_locale.so -> libboost_locale.so.1.65.0
-rwxr-xr-x 1 root root 1161984 Oct 1 16:11 libboost_locale.so.1.65.0
-rw-r--r-- 1 root root 3029602 Oct 1 16:11 libboost_log.a
-rw-r--r-- 1 root root 2435950 Oct 1 16:11 libboost_log_setup.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_log_setup.so -> libboost_log_setup.so.1.65.0
-rwxr-xr-x 1 root root 1107160 Oct 1 16:11 libboost_log_setup.so.1.65.0
lrwxrwxrwx 1 root root 22 Oct 1 16:11 libboost_log.so -> libboost_log.so.1.65.0
-rwxr-xr-x 1 root root 1146984 Oct 1 16:11 libboost_log.so.1.65.0
-rw-r--r-- 1 root root 659100 Oct 1 16:11 libboost_math_c99.a
-rw-r--r-- 1 root root 553156 Oct 1 16:11 libboost_math_c99f.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_math_c99f.so -> libboost_math_c99f.so.1.65.0
-rwxr-xr-x 1 root root 83384 Oct 1 16:11 libboost_math_c99f.so.1.65.0
-rw-r--r-- 1 root root 578542 Oct 1 16:11 libboost_math_c99l.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_math_c99l.so -> libboost_math_c99l.so.1.65.0
-rwxr-xr-x 1 root root 83824 Oct 1 16:11 libboost_math_c99l.so.1.65.0
lrwxrwxrwx 1 root root 27 Oct 1 16:11 libboost_math_c99.so -> libboost_math_c99.so.1.65.0
-rwxr-xr-x 1 root root 103384 Oct 1 16:11 libboost_math_c99.so.1.65.0
-rw-r--r-- 1 root root 2933306 Oct 1 16:11 libboost_math_tr1.a
-rw-r--r-- 1 root root 2923974 Oct 1 16:11 libboost_math_tr1f.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_math_tr1f.so -> libboost_math_tr1f.so.1.65.0
-rwxr-xr-x 1 root root 456008 Oct 1 16:11 libboost_math_tr1f.so.1.65.0
-rw-r--r-- 1 root root 2901944 Oct 1 16:11 libboost_math_tr1l.a
lrwxrwxrwx 1 root root 28 Oct 1 16:11 libboost_math_tr1l.so -> libboost_math_tr1l.so.1.65.0
-rwxr-xr-x 1 root root 414672 Oct 1 16:11 libboost_math_tr1l.so.1.65.0
lrwxrwxrwx 1 root root 27 Oct 1 16:11 libboost_math_tr1.so -> libboost_math_tr1.so.1.65.0
-rwxr-xr-x 1 root root 428872 Oct 1 16:11 libboost_math_tr1.so.1.65.0
-rw-r--r-- 1 root root 167818 Oct 1 16:11 libboost_prg_exec_monitor.a
lrwxrwxrwx 1 root root 35 Oct 1 16:11 libboost_prg_exec_monitor.so -> libboost_prg_exec_monitor.so.1.65.0
-rwxr-xr-x 1 root root 94432 Oct 1 16:11 libboost_prg_exec_monitor.so.1.65.0
-rw-r--r-- 1 root root 1320724 Oct 1 16:11 libboost_program_options.a
lrwxrwxrwx 1 root root 34 Oct 1 16:11 libboost_program_options.so -> libboost_program_options.so.1.65.0
-rwxr-xr-x 1 root root 591024 Oct 1 16:11 libboost_program_options.so.1.65.0
-rw-r--r-- 1 root root 612306 Oct 1 16:11 libboost_python.a
lrwxrwxrwx 1 root root 25 Oct 1 16:11 libboost_python.so -> libboost_python.so.1.65.0
-rwxr-xr-x 1 root root 369992 Oct 1 16:11 libboost_python.so.1.65.0
-rw-r--r-- 1 root root 39266 Oct 1 16:11 libboost_random.a
lrwxrwxrwx 1 root root 25 Oct 1 16:11 libboost_random.so -> libboost_random.so.1.65.0
-rwxr-xr-x 1 root root 31776 Oct 1 16:11 libboost_random.so.1.65.0
-rw-r--r-- 1 root root 2961168 Oct 1 16:11 libboost_regex.a
lrwxrwxrwx 1 root root 24 Oct 1 16:11 libboost_regex.so -> libboost_regex.so.1.65.0
-rwxr-xr-x 1 root root 1420512 Oct 1 16:11 libboost_regex.so.1.65.0
-rw-r--r-- 1 root root 1114070 Oct 1 16:11 libboost_serialization.a
lrwxrwxrwx 1 root root 32 Oct 1 16:11 libboost_serialization.so -> libboost_serialization.so.1.65.0
-rwxr-xr-x 1 root root 440448 Oct 1 16:11 libboost_serialization.so.1.65.0
-rw-r--r-- 1 root root 208580 Oct 1 16:11 libboost_signals.a
lrwxrwxrwx 1 root root 26 Oct 1 16:11 libboost_signals.so -> libboost_signals.so.1.65.0
-rwxr-xr-x 1 root root 119336 Oct 1 16:11 libboost_signals.so.1.65.0
-rw-r--r-- 1 root root 59616 Oct 1 16:11 libboost_stacktrace_addr2line.a
lrwxrwxrwx 1 root root 39 Oct 1 16:11 libboost_stacktrace_addr2line.so -> libboost_stacktrace_addr2line.so.1.65.0
-rwxr-xr-x 1 root root 49224 Oct 1 16:11 libboost_stacktrace_addr2line.so.1.65.0
-rw-r--r-- 1 root root 39630 Oct 1 16:11 libboost_stacktrace_basic.a
lrwxrwxrwx 1 root root 35 Oct 1 16:11 libboost_stacktrace_basic.so -> libboost_stacktrace_basic.so.1.65.0
-rwxr-xr-x 1 root root 35824 Oct 1 16:11 libboost_stacktrace_basic.so.1.65.0
-rw-r--r-- 1 root root 2946 Oct 1 16:11 libboost_stacktrace_noop.a
lrwxrwxrwx 1 root root 34 Oct 1 16:11 libboost_stacktrace_noop.so -> libboost_stacktrace_noop.so.1.65.0
-rwxr-xr-x 1 root root 8496 Oct 1 16:11 libboost_stacktrace_noop.so.1.65.0
-rw-r--r-- 1 root root 62116 Oct 1 16:11 libboost_system.a
lrwxrwxrwx 1 root root 25 Oct 1 16:11 libboost_system.so -> libboost_system.so.1.65.0
-rwxr-xr-x 1 root root 20944 Oct 1 16:11 libboost_system.so.1.65.0
-rw-r--r-- 1 root root 2463292 Oct 1 16:11 libboost_test_exec_monitor.a
-rw-r--r-- 1 root root 297182 Oct 1 16:11 libboost_thread.a
lrwxrwxrwx 1 root root 25 Oct 1 16:11 libboost_thread.so -> libboost_thread.so.1.65.0
-rwxr-xr-x 1 root root 187920 Oct 1 16:11 libboost_thread.so.1.65.0
-rw-r--r-- 1 root root 22672 Oct 1 16:11 libboost_timer.a
lrwxrwxrwx 1 root root 24 Oct 1 16:11 libboost_timer.so -> libboost_timer.so.1.65.0
-rwxr-xr-x 1 root root 24960 Oct 1 16:11 libboost_timer.so.1.65.0
-rw-r--r-- 1 root root 112536 Oct 1 16:11 libboost_type_erasure.a
lrwxrwxrwx 1 root root 31 Oct 1 16:11 libboost_type_erasure.so -> libboost_type_erasure.so.1.65.0
-rwxr-xr-x 1 root root 73568 Oct 1 16:11 libboost_type_erasure.so.1.65.0
-rw-r--r-- 1 root root 2433124 Oct 1 16:11 libboost_unit_test_framework.a
lrwxrwxrwx 1 root root 38 Oct 1 16:11 libboost_unit_test_framework.so -> libboost_unit_test_framework.so.1.65.0
-rwxr-xr-x 1 root root 1052944 Oct 1 16:11 libboost_unit_test_framework.so.1.65.0
-rw-r--r-- 1 root root 3857126 Oct 1 16:11 libboost_wave.a
lrwxrwxrwx 1 root root 23 Oct 1 16:11 libboost_wave.so -> libboost_wave.so.1.65.0
-rwxr-xr-x 1 root root 1879896 Oct 1 16:11 libboost_wave.so.1.65.0
-rw-r--r-- 1 root root 752452 Oct 1 16:11 libboost_wserialization.a
lrwxrwxrwx 1 root root 33 Oct 1 16:11 libboost_wserialization.so -> libboost_wserialization.so.1.65.0
-rwxr-xr-x 1 root root 312616 Oct 1 16:11 libboost_wserialization.so.1.65.0

标签:11,16,--,boost,c++,测试,root,Oct,libboost
From: https://www.cnblogs.com/lightdb/p/17738819.html

相关文章

  • c/c++获取uuid
    c/c++标准库中没有自带的uuid工具函数/类,可以使用三方库libuuid,boost,或者手工实现,如下:[zjh@hs-10-20-xxxlib]$sudoyuminstalllibuuid-devel[sudo]passwordforzjh:Loadedplugins:fastestmirror,langpacksLoadingmirrorspeedsfromcachedhostfilebase......
  • C++中mutable关键字学习
    转自:https://liam.page/2017/05/25/the-mutable-keyword-in-Cxx/,讲的很好。1.介绍mutable即可变的,mutable只能用来修饰类的数据成员;而被mutable修饰的数据成员,可以在const成员函数中修改。例子:classHashTable{public://...std::stringlookup(conststd::......
  • 在VS Code中配置C/C++
    之前因为学了一点html,所以下了一个VSCode来写html代码。今天要写C++的代码,以前都是用VS写的。但是突然想了一下既然都装了VSCode,为啥不配置一下。配置好了后以后写C/C++代码也不用打开繁重的VS了。而且VSCode还能加很多插件。说干就干,上网找了资料,终于配置好了。还是有蛮多坑......
  • C++常见算法&数据结构模版
    各种常见算法&数据结构模板1.最长不下降子序列(LIS)1.1\(O(n^2)\)做法点击查看代码for(inti=1;i<=n;i++){ cin>>a[i]; dp[i]=1; } for(inti=1;i<=n;i++){ for(intj=1;j<i;j++){ if(a[i]>a[j]){ dp[i]=max(dp[i],dp[j]+......
  • C++ STL标准容器的特点和典型的使用场景
    概念和作用C++标准模板库(StandardTemplateLibrary,STL)提供了一组通用的模板类和函数,用于处理常见的数据结构和算法。STL中的标准容器是其中的重要组成部分,它们提供了不同的数据结构和操作方式,适用于各种不同的使用场景。说白了,就是每一种容器代表一种特定的数据结构。我们在学C......
  • C++对拍模版
    Windowscheck.cpp#include<bits/stdc++.h>usingnamespacestd;intmain(){ while(true) { system("data.exe"); system("std.exe"); system("brute.exe"); if(system("fcstd.outbrute.out"))......
  • C++快读、快写模版
    inlineintread(){ charch=getchar(); intx=0,f=1; while(!isdigit(ch))if(ch=='-')f=-1,ch=getchar(); while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); returnx*f;}inlinevoidprint(intn){if......
  • 【14.0】中间件、跨域资源共享、后台任务、测试用例
    【一】中间件【1】中间件介绍FastAPI中间件是在处理请求和响应的过程中介入的组件,允许你在请求到达处理函数之前或响应离开处理函数之后执行一些逻辑。中间件在FastAPI中起到非常灵活的作用,可以用于日志记录、身份验证、异常处理等。【2】中间件的工作原理(1)注册中间件......
  • Python代码转换成C++
    Python和C++是两种不同的编程语言,但它们都有各自的优势和适用场景。在某些情况下,我们可能需要将Python代码转换成C++代码,以获得更高的执行效率或更好的性能。本文将从多个方面介绍如何将Python代码转换为C++代码。一、代码结构Python和C++在代码结构上存在一些差异。Python是一种解......
  • C/C++学习 -- 流加密算法(RC4算法)
    在信息安全领域,加密算法扮演着至关重要的角色。其中,RC4算法是一种广泛使用的流密码算法,用于数据的保密性和机密性。本文将深入探讨RC4算法的概述、特点、原理,以及提供C语言和C++语言实现RC4算法的代码案例。一、RC4算法概述RC4算法,又称RivestCipher4或Ron'sCode4,是一种流密码(St......