Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_max_body_size 报错 #379

Open
naonao-cola opened this issue Dec 9, 2024 · 3 comments
Open

http_max_body_size 报错 #379

naonao-cola opened this issue Dec 9, 2024 · 3 comments

Comments

@naonao-cola
Copy link

#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: 找到一个或多个多重定义的符号

@izhengfan
Copy link
Contributor

izhengfan commented Dec 17, 2024

这个值在库里已经定义过,你应该声明(DEC)而不是定义(DEF)它

@naonao-cola
Copy link
Author

这个值在库里已经定义过,你应该声明(DEC)而不是定义(DEF)它

图片
图片
请问下这种我发送图片的这种,该怎么传送,接收

@izhengfan
Copy link
Contributor

你这是另外一个问题了吧,我不懂,建议你新开一个issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants