Skip to content

http_max_body_size 报错 #379

@naonao-cola

Description

@naonao-cola
#include <iostream>
#include <thread>
#include "co/all.h"
//#include "co/http.h"
//#include "co/flag.h"

//DEF_uint32(http_max_body_size, 40 << 20, "#2 max size of http body, default: 8M");


void cb(const http::Req& req, http::Res& res) {
    if (req.is_method_get()) {
        if (req.url() == "/hello") {

            res.set_status(200);
            res.set_body("hello world");

            std::cout<<"============"<<std::endl;

            const char* data = req.body();
            std::cout<<req.body()<<std::endl;

        } else {
            res.set_status(404);
        }
    } else {
        res.set_status(405); // method not allowed
    }
}

void test_http(){
    http::Server().on_req(cb).start("0.0.0.0", 80);
}

int main(int argc, char** argv) {
    std::cout << "hello world!" << std::endl;
    FLG_http_max_body_size =40<<20;
    std::thread t1(test_http);
    while(1){}
    return 0;
}

以上代码报错:

❗ error: main.cpp
src\main.cpp(36): error C2065: “FLG_http_max_body_size”: 未声明的标识符

#include <iostream>
#include <thread>
#include "co/all.h"
//#include "co/http.h"
//#include "co/flag.h"

DEF_uint32(http_max_body_size, 40 << 20, "#2 max size of http body, default: 8M");


void cb(const http::Req& req, http::Res& res) {
    if (req.is_method_get()) {
        if (req.url() == "/hello") {

            res.set_status(200);
            res.set_body("hello world");

            std::cout<<"============"<<std::endl;

            const char* data = req.body();
            std::cout<<req.body()<<std::endl;

        } else {
            res.set_status(404);
        }
    } else {
        res.set_status(405); // method not allowed
    }
}

void test_http(){
    http::Server().on_req(cb).start("0.0.0.0", 80);
}

int main(int argc, char** argv) {
    std::cout << "hello world!" << std::endl;
    FLG_http_max_body_size =40<<20;
    std::thread t1(test_http);
    while(1){}
    return 0;
}

加上定义也报错
error: co.lib(http.cc.obj) : error LNK2005: "unsigned int FLG_http_max_body_size" (?FLG_http_max_body_size@@3ia) 已经在 main.cpp.obj 中定义
build\windows\x64\debug\coost.exe : fatal error LNK1169: 找到一个或多个多重定义的符号

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions