目錄
升級(jí)gcc版本
下載cpp-httplib的zip安裝包,上傳到服務(wù)器
?編輯?簡(jiǎn)單使用
首先打開gittee,搜索cpp-httplib,選擇其中一個(gè)即可
也可以點(diǎn)下方鏈接?
cpp-httplib庫:cpp-httplib: cpp-httplib (gitee.com)
注意:cpp-httplib在使用的時(shí)候需要使用較新版本的gcc,centos 7默認(rèn)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)?
?用老的編譯器,要么編譯不通過,要么直接拿報(bào)錯(cuò),如果需要升級(jí)gcc版本,可按照如下步驟:
升級(jí)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)查看安裝結(jié)果
[root@iZbp1f6xfzvrfki6wwxqjvZ ~]# ls /opt/rh/devtoolset-7/
enable ?root?
?4)啟動(dòng),細(xì)節(jié),命令行啟動(dòng)只能在本會(huì)話有效
scl enable devtoolset-7 bash
//因此如果要使它每次都生效,將上述指令添加進(jìn)如下文件,這樣每次啟動(dòng)的時(shí)候,都會(huì)執(zhí)行這個(gè)scl命令,如此每次登錄的時(shí)候,都是較新的gcc
vim ~/.bash_profile
下載cpp-httplib的zip安裝包,上傳到服務(wù)器
最新的cpp-httplb在使用的時(shí)候,如果gcc不是特別新的話就有可能會(huì)有運(yùn)行時(shí)錯(cuò)誤的問題
建議:cpp-httplib 0.7.15
1)選擇標(biāo)簽
2)選擇0.7.15版本
?3)開始下載
4)傳送到linux系統(tǒng)上?
5)對(duì)該壓縮包進(jìn)行解壓?
unzip cpp-httplib-v0.7.15.zip?
后續(xù)我們主要使用httplib.h這個(gè)庫?
?簡(jiǎn)單使用
#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;
}
驗(yàn)證是否運(yùn)行文章來源:http://www.zghlxwxcb.cn/news/detail-838871.html
netstat -ntlp?文章來源地址http://www.zghlxwxcb.cn/news/detail-838871.html
到了這里,關(guān)于【Linux】cpp-httplib庫的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!