01 centos7中cmake配置crow开发环境

一、搭建开发环境

1.1 c++开发环境

yum -y install gcc gcc-c++ gdb git

1.2 安装crow所需依赖

yum install boost boost-devel
yum install openssl openssl-devel

1.3 安装cmake_3.27.9

可以借鉴此安装:https://blog.csdn.net/i_coding_/article/details/131883590

二、Crow和Asio

2.1 下载Crow

从Crow的github仓库拉取仓库,在源码根目录下找到include子目录,其中包括了corw.h以及crow文件夹

2.2 下载Asio

Asio的官网是:http://think-async.com/Asio/,其发布版本放在了sourceforge:https://sourceforge.net/projects/asio/files/asio/,我使用的版本1.28.2,下载之后也是只有一个include目录,目录下包含了asio.hpp和asio文件夹。

三、测试项目搭建

3.1 项目目录

创建crowTest项目:mkdir crowTest && cd crowTest

.
├── build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   ├── cmake_install.cmake
│   ├── Makefile
│   └── server_manage
├── CMakeLists.txt
├── include
│   ├── asio
│   ├── asio.hpp
│   ├── crow
│   └── crow.h
└── main.cpp

include:我们将2.1下载的后include目录中crow目录和crow.h拷贝到项目include目录中,以及2.2中的下载的后include目录中asio目录和asio.hpp拷贝到项目include目录中

3.2 cmake配置

CMakeLists.txt:

cmake_minimum_required(VERSION 3.27)
project(crowTest)

set(CMAKE_CXX_STANDARD 11)

include_directories(${PROJECT_SOURCE_DIR}/include)

add_executable(crowTest main.cpp)
target_link_libraries(crowTest pthread)

3.3 编译项目

写一个简单的测试主程序:
main.cpp:

#include<iostream>
using namespace std;
#include "crow.h"

int main(){
    crow::SimpleApp app; //define your crow application

    //define your endpoint at the root directory
    CROW_ROUTE(app, "/")([](){
        return "Hello world";
    });

    //set the port, set the app to run on multiple threads, and run the app
    app.port(8667).multithreaded().run();
	return 0;
}

进入bulid进行编译:

cd build
cmake ..
make
./crowTest # 启动项目

启动成功显示:

(2024-07-01 01:36:35) [INFO    ] Crow/master server is running at http://0.0.0.0:8667 using 4 threads
(2024-07-01 01:36:35) [INFO    ] Call `app.loglevel(crow::LogLevel::Warning)` to hide Info level logs.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值