一、功能总览
1.1 项目介绍
- 实现一个类似牛客、leetcode的在线OJ系统,用户可以选择试题,并提交代码,通过网络传输,上传到服务器后台,后台对代码进行编译运行,并把测试结果反馈给客户端浏览器
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d774ea92ecbdd9928b8a9c326b56e896.png)
1.2 环境搭建
- 利用cpp-httplib开源库:搭建一个http服务,不需要关心 tcp 和 http 的建立和 url 解析过程,只要注册对应的方法。
克隆仓库:git clone https://gitee.com/iqxg/cpp-httplib.git
- 升级gcc,cpp-httplib库依赖 C++ 11 中的正则表达式,而 Centos7 自带的 gcc4.8 正则表达式有 bug。
1.下载高版本gcc:bash中输入以下命令
sudo yum -y install centos-release-scl
sudo yum -y install devtoolset-7-gcc devtoolset-7-gcc-c++ devtoolset-7-binutils
2.设置默认启动高版本gcc
打开文件
vim ~/.bash_profile
在最后添加:
scl enable devtoolset-7 bash
重启gcc
source ~/.bash_profile
- 下载Jsoncpp
yum install jsoncpp
yum install jsoncpp-devel
- 下载谷歌ctemplate,boost
sudo yum install -y snappy-devel boost-devel zlib-devel.x86_64 python-pip
sudo pip install BeautifulSoup4
git clone https://gitee.com/HGtz2222/ThirdPartLibForCpp.git
cd ./ThirdPartLibForCpp/el7.x86_64/
sh install.sh
1.3 cpp-httplib库测试
#include <iostream>
#include <string>
#include "httplib.h"
int main()
{
httplib::Server http_svr;
http_svr.Get("/index", [](const httplib::Request& req, httplib::Response& resp){
std::cout << req.method << " " << req.path << " " << req.version << std::endl;
std::string html = "<html>this is Linux~~<html>";
resp.set_content(html, "text/html");
}