错误:在Windows和WSL 2上运行Mongoose代码时需要标识符或未声明的变量

nle07wnf  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(178)

我试图从https://github.com/cesanta/mongoose运行示例代码,但是,在运行make并按照安装说明操作后,我得到了这个错误。我也尝试在WSL 2上运行它,但没有用。但是,如果我在我的Linux笔记本电脑上运行示例,一切正常。

❯ make
gcc                       main.c mongoose.c        -W -Wall -Wextra -g -I.   -lws2_32             -DMG_ENABLE_LINES  -o example
In file included from main.c:6:
mongoose.h:1:1: error: expected identifier or '(' before '.' token
    1 | ../../mongoose.h
      | ^
main.c:15:23: warning: 'struct mg_connection' declared inside parameter list will not be visible outside of this definition or declaration
   15 | static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
      |                       ^~~~~~~~~~~~~
main.c: In function 'fn':
main.c:16:13: error: 'MG_EV_OPEN' undeclared (first use in this function)
   16 |   if (ev == MG_EV_OPEN) {
      |             ^~~~~~~~~~
main.c:16:13: note: each undeclared identifier is reported only once for each function it appears in
main.c:18:20: error: 'MG_EV_HTTP_MSG' undeclared (first use in this function)
   18 |   } else if (ev == MG_EV_HTTP_MSG) {
      |                    ^~~~~~~~~~~~~~
main.c:20:9: warning: implicit declaration of function 'mg_http_match_uri' [-Wimplicit-function-declaration]
   20 |     if (mg_http_match_uri(hm, "/websocket")) {
      |         ^~~~~~~~~~~~~~~~~
main.c:23:7: warning: implicit declaration of function 'mg_ws_upgrade' [-Wimplicit-function-declaration]
   23 |       mg_ws_upgrade(c, hm, NULL);
      |       ^~~~~~~~~~~~~
.....
.....
make: *** [Makefile:22: example] Error 1

字符串

68de4m5k

68de4m5k1#

我在Windows上也遇到了这个问题。我相信这是Mingw特有的问题,以及.c/.h文件使用相对路径而不使用#include语句的方式。
在您所在的examples目录中,将有一个:

  • mongoose.c
  • mongoose.h

如果你看这些文件的内容,

../../mongoose.c

字符串
如果您更改(两个)这些文件,

#include "../../mongoose.c"


然后Mingw将解析文件,编译将成功。

相关问题