Apache模块创建教程包含有错误的代码。怎么修?

时间:2015-10-21 18:17:46

标签: c apache gcc compiler-errors compiler-warnings

我访问了以下URL,了解有关构建apache模块的说明:

https://httpd.apache.org/docs/2.4/developer/modguide.html

它在页面中间说明自定义模块处理apache配置文件中的条目需要类似以下代码:

static const command_rec example_directives[] =
{
    AP_INIT_TAKE1("exampleEnabled", example_set_enabled, NULL, RSRC_CONF, "Enable or disable mod_example"),
    AP_INIT_TAKE1("examplePath", example_set_path, NULL, RSRC_CONF, "The path to whatever"),
    AP_INIT_TAKE2("exampleAction", example_set_action, NULL, RSRC_CONF, "Special action value!"),
    { NULL }
};

使用无gcc选项在apxs下编译正常。它不会通过扩展错误检查进行编译。例如,我发出了这个命令:

apxs -i -a -Wc,Werror -Wc,-Wall -Wc,-Wextra -Wc,-O2 -c ./sample.c --enable-debug=YES

尝试执行gcc -Wall -Wextra -O2 sample.c并且我收到的错误是:

./sample.c:178: warning: missing initializer
./sample.c:178: warning: (near initialization for 'example_directives[4].func')

错误行指向仅包含{ NULL }的行。

apache模块教程还建议我们使用函数与程序员很少使用的参数。结果,我一直收到这些警告:

warning: unused parameter

如何在启用扩展错误检查的情况下解决所有这些错误?

1 个答案:

答案 0 :(得分:0)

gcc希望你显然初始化结构的所有成员。尝试用{NULL,{NULL},NULL,0,0,NULL}替换最后一个条目。这些值应该与/usr/include/httpd/http_config.h中常见的command_rec结构定义相匹配