【Linux】cpp-httplib库

目录

升级gcc版本

下载cpp-httplib的zip安装包,上传到服务器

​编辑 简单使用


首先打开gittee,搜索cpp-httplib,选择其中一个即可

也可以点下方链接 

cpp-httplib库:cpp-httplib: cpp-httplib (gitee.com)

注意:cpp-httplib在使用的时候需要使用较新版本的gcc,centos 7默认gcc 4.8.5

通过如下命令查看gcc版本

[root@iZbp1f6xfzvrfki6wwxqjvZ ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 

 用老的编译器,要么编译不通过,要么直接拿报错,如果需要升级gcc版本,可按照如下步骤:


升级gcc版本

1)安装scl源

yum install centos-release-scl scl-utils-build

2) 安装7版本的gcc

yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++ 

3)查看安装结果

[root@iZbp1f6xfzvrfki6wwxqjvZ ~]# ls /opt/rh/devtoolset-7/
enable  root 

 4)启动,细节,命令行启动只能在本会话有效

scl enable devtoolset-7 bash

//因此如果要使它每次都生效,将上述指令添加进如下文件,这样每次启动的时候,都会执行这个scl命令,如此每次登录的时候,都是较新的gcc

vim ~/.bash_profile

下载cpp-httplib的zip安装包,上传到服务器

最新的cpp-httplb在使用的时候,如果gcc不是特别新的话就有可能会有运行时错误的问题

建议:cpp-httplib 0.7.15

1)选择标签

2)选择0.7.15版本

 3)开始下载

4)传送到linux系统上 

5)对该压缩包进行解压 

unzip cpp-httplib-v0.7.15.zip 

后续我们主要使用httplib.h这个库 

 简单使用

 #include "cpp-httplib/httplib.h"    
      
  int main()    
  {    
    httplib::Server svr;    
    //10.101.101.1/hi    
    svr.Get("/hi",[](const httplib::Request &req,httplib::Response &resp){    
       resp.set_content("hello world!","text/plain; charset=utf-8");    
       });    
    svr.listen("0.0.0.0",8082);                                                                                                        
    return 0;    
  }    
  

验证是否运行

netstat -ntlp 

  • 24
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值