c++ - 用 C++ 实现 Mongoose 服务器

标签 c++ mongoose-web-server

我最近尝试使用 code::blocks 编译链接在 Mongoose 项目网站上的示例,但遇到了某些错误。由于我不知道哪里出错了,所以我将列出我在此过程中所做的一切。

使用的操作系统:Microsoft Windows 8(64 位)

Code::Blocks 使用的版本:codeblocks-12.11 with MinGW

Code::Blocks 使用的编译器:GNU GCC 编译器

以下是 Code::Blocks 生成的构建消息:

D:\pdthrow\cppprojects\server\mongoose.c|176|warning: "INT64_MAX" redefined [enabled by default]| e:\8\code blocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\..\include\stdint.h|95|note: this is the location of the previous definition|
D:\pdthrow\cppprojects\server\mongoose.c||In function 'set_ports_option':|
D:\pdthrow\cppprojects\server\mongoose.c|4626|warning: format '%d' expects argument of type 'int', but argument 6 has type 'DWORD' [-Wformat]|
D:\pdthrow\cppprojects\server\mongoose.c||In function 'getreq':|
D:\pdthrow\cppprojects\server\mongoose.c|5027|warning: implicit declaration of function '_strtoi64' [-Wimplicit-function-declaration]| obj\Debug\mongoose.o||In function `sockaddr_to_string':|
D:\pdthrow\cppprojects\server\mongoose.c|614|undefined reference to `inet_ntoa@4'| obj\Debug\mongoose.o||In function `poll':|
D:\pdthrow\cppprojects\server\mongoose.c|1258|undefined reference to `select@20'|
D:\pdthrow\cppprojects\server\mongoose.c|1260|undefined reference to `__WSAFDIsSet@8'| obj\Debug\mongoose.o||In function `set_non_blocking_mode':|
D:\pdthrow\cppprojects\server\mongoose.c|1374|undefined reference to `ioctlsocket@12'| obj\Debug\mongoose.o||In function `push':|
D:\pdthrow\cppprojects\server\mongoose.c|1499|undefined reference to `send@16'| obj\Debug\mongoose.o||In function `pull':|
D:\pdthrow\cppprojects\server\mongoose.c|1526|undefined reference to `recv@16'| obj\Debug\mongoose.o||In function `conn2':|
D:\pdthrow\cppprojects\server\mongoose.c|2596|undefined reference to `gethostbyname@4'|
D:\pdthrow\cppprojects\server\mongoose.c|2598|undefined reference to `socket@12'|
D:\pdthrow\cppprojects\server\mongoose.c|2603|undefined reference to `htons@4'|
D:\pdthrow\cppprojects\server\mongoose.c|2605|undefined reference to `connect@12'|
D:\pdthrow\cppprojects\server\mongoose.c|2608|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `prepare_cgi_environment':|
D:\pdthrow\cppprojects\server\mongoose.c|3298|undefined reference to `ntohs@4'| obj\Debug\mongoose.o||In function `get_remote_ip':|
D:\pdthrow\cppprojects\server\mongoose.c|4274|undefined reference to `ntohl@4'| obj\Debug\mongoose.o||In function `redirect_to_https_port':|
D:\pdthrow\cppprojects\server\mongoose.c|4422|undefined reference to `ntohs@4'| obj\Debug\mongoose.o||In function `close_all_listening_sockets':|
D:\pdthrow\cppprojects\server\mongoose.c|4542|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `parse_port_string':|
D:\pdthrow\cppprojects\server\mongoose.c|4568|undefined reference to `htonl@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4569|undefined reference to `htons@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4580|undefined reference to `htons@4'| obj\Debug\mongoose.o||In function `set_ports_option':|
D:\pdthrow\cppprojects\server\mongoose.c|4611|undefined reference to `socket@12'|
D:\pdthrow\cppprojects\server\mongoose.c|4615|undefined reference to `setsockopt@20'|
D:\pdthrow\cppprojects\server\mongoose.c|4622|undefined reference to `bind@12'|
D:\pdthrow\cppprojects\server\mongoose.c|4624|undefined reference to `listen@8'|
D:\pdthrow\cppprojects\server\mongoose.c|4627|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4632|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `close_socket_gracefully':|
D:\pdthrow\cppprojects\server\mongoose.c|4913|undefined reference to `setsockopt@20'|
D:\pdthrow\cppprojects\server\mongoose.c|4917|undefined reference to `shutdown@8'|
D:\pdthrow\cppprojects\server\mongoose.c|4932|undefined reference to `closesocket@4'| obj\Debug\mongoose.o||In function `mg_connect':|
D:\pdthrow\cppprojects\server\mongoose.c|4972|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4977|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|4987|undefined reference to `getsockname@12'| obj\Debug\mongoose.o||In function `worker_thread':|
D:\pdthrow\cppprojects\server\mongoose.c|5175|undefined reference to `ntohs@4'|
D:\pdthrow\cppprojects\server\mongoose.c|5178|undefined reference to `ntohl@4'| obj\Debug\mongoose.o||In function `set_sock_timeout':|
D:\pdthrow\cppprojects\server\mongoose.c|5238|undefined reference to `setsockopt@20'|
D:\pdthrow\cppprojects\server\mongoose.c|5239|undefined reference to `setsockopt@20'| obj\Debug\mongoose.o||In function `accept_new_connection':|
D:\pdthrow\cppprojects\server\mongoose.c|5249|undefined reference to `accept@12'|
D:\pdthrow\cppprojects\server\mongoose.c|5250|undefined reference to `ntohl@4'|
D:\pdthrow\cppprojects\server\mongoose.c|5253|undefined reference to `closesocket@4'|
D:\pdthrow\cppprojects\server\mongoose.c|5260|undefined reference to `getsockname@12'|
D:\pdthrow\cppprojects\server\mongoose.c|5267|undefined reference to `setsockopt@20'| obj\Debug\mongoose.o||In function `mg_stop':|
D:\pdthrow\cppprojects\server\mongoose.c|5384|undefined reference to `WSACleanup@0'| obj\Debug\mongoose.o||In function `mg_start':|
D:\pdthrow\cppprojects\server\mongoose.c|5397|undefined reference to `WSAStartup@8'| ||=== Build finished: 41 errors, 3 warnings (0 minutes, 3 seconds) ===|

请帮助我了解哪里出了问题。我的动机是在我目前从事的项目中实现适用于 Windows 和 Linux 的 Mongooser Web 服务器 API。

最佳答案

你有一个链接问题,你需要链接winsock库Ws2_32.lib,你可以找到一个关于将库添加到code::blocks的教程here ,你不需要设置任何目录,只需将 Ws2_32.lib 添加到步骤 5 的链接器中

关于c++ - 用 C++ 实现 Mongoose 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18686875/

相关文章:

c++ - Lua:在 native lua 中编译,但在使用 LuaJIT 和 sol2 的 C++ 中出错

python - 在 Mongoose 中运行 Python 脚本

request - 我可以限制 mongoose Web 服务器不接受 http 请求,而只接受来自主机应用程序的请求吗

从 mongoose begin_request_handler 回调调用函数

c++ - Qt C++ QDomDocument,递归迭代 XML 数据,检索没有子数据的文本元素

c++ - Node.JS,C++ 模块 : why I have segfault when I try to call Length method of Local<Array>?

C++ 17类模板参数类型推导——可读性

c++ - _mkdir给出错误的错误窗口

c++ - mongoose web 服务器 helloworld 程序

c - malloc mongoose webserver http post body 并将其传递给线程