使用 创建 Web 服务器proxygen
时,我将其包含proxygen::HTTPServer
在另一个子目录中,但出现错误。
但是我在另一个目录中包含了相同的库,但我无法得到错误。
In file included from /usr/local/include/folly/FBString.h:60:0,
from /usr/local/include/folly/Demangle.h:19,
from /usr/local/include/folly/Conv.h:40,
from /usr/local/include/folly/String.h:27,
from /usr/local/include/folly/io/async/SSLContext.h:35,
from /usr/local/include/wangle/ssl/SSLContextConfig.h:19,
from /usr/local/include/proxygen/httpserver/HTTPServer.h:12,
from /home/skyend/ds/sentencer-backend-engine/include/router/src/Router.h:9,
from /home/skyend/ds/sentencer-backend-engine/include/router/src/Router.cpp:5:
/usr/local/include/folly/memory/Malloc.h: In lambda function:
/usr/local/include/folly/memory/Malloc.h:196:38: error: inconsistent types ‘int’ and ‘bool’ deduced for lambda return type
return (origAllocated != *counter);
包括/路由器/CMakeListx.txt
add_library(sbx_router src/Router.cpp src/Router.h)
target_link_libraries(sbx_router r3 folly)
包括/路由器/src/Router.h(错误)
#include <iostream>
#include <router/src/r3.h>
#include <proxygen/httpserver/HTTPServer.h>
#include <proxygen/httpserver/RequestHandlerFactory.h>
src/http/service/CMakeLists.txt
add_library(sbx_services
LoggingHandlerFactory.h)
src/http/service/LoggingHandlerFactory.h(编译好)
#include "libs/stringUtils.h"
#include <proxygen/httpserver/HTTPServer.h>
#include <proxygen/httpserver/RequestHandlerFactory.h>
#include <boost/algorithm/string.hpp>
#include <vector>
namespace sbx::http::service {
class LoggingHandlerFactory : public proxygen::RequestHandlerFactory {
public:
void onServerStart(folly::EventBase * /*evb*/) noexcept override {}
void onServerStop() noexcept override {}
proxygen::RequestHandler *onRequest(proxygen::RequestHandler * nextHandler, proxygen::HTTPMessage * msg) noexcept override {
std::string method = "unknown";
if( msg->getMethod().hasValue() ) {
method = proxygen::methodToString(msg->getMethod().value());
}
std::cout << "[" << method << "] " << msg->getPath() << std::endl;
if( nextHandler != nullptr ){
return nextHandler;
}
}
};
}
CMakeLists.txt
...
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
# Things to always src as flags. Change as needed.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
# Build-type specific flags. Change as needed.
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
...
为什么会出现错误?
路由器.h:9
#include <proxygen/httpserver/HTTPServer.h>
路由器.cpp:5
#include <proxygen/httpserver/HTTPServer.h>
谢谢你的帮助。