简体   繁体   English

没有 -Wdeclaration-after-statement 的 PostgreSQL C 扩展

[英]PostgreSQL C Extensions without -Wdeclaration-after-statement

Currently, when I compile my extension I get,目前,当我编译我的扩展时,我得到,

warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
   57 |  uint32 n = fctx->n;

PostgreSQL currently uses -Wdeclaration-after-statement during compilation. PostgreSQL 当前在编译期间使用-Wdeclaration-after-statement They set this option specifically in their pgxs global make file on my machine that's at,他们在我的机器上的pgxs全局 make 文件中专门设置了这个选项,

/usr/lib/postgresql/13/lib/pgxs/src/Makefile.global

It is set with their CFLAGS ,它是用他们的CFLAGS设置的,

CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer

Is there anyway to disable -Wdeclaration-after-statement or does every PostgreSQL extension author have to adopt this same convention?无论如何要禁用-Wdeclaration-after-statement还是每个 PostgreSQL 扩展作者都必须采用相同的约定? Can I override CFLAGS in my extension?我可以在我的扩展中覆盖 CFLAGS 吗?

Probably you can override it by the instructions described in the link可能您可以通过链接中描述的说明覆盖它

The variable PG_CFLAGS will be appended to CFLAGS , so just add -Wno-declaration-after-statement变量PG_CFLAGS将被附加到CFLAGS ,所以只需添加-Wno-declaration-after-statement

I was able to squelch these warnings by ending my extension's Makefile with,我能够通过结束我的扩展的Makefile来消除这些警告,

$(OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)

Thanks goes out RhodiumToad on ircs://irc.libera.chat:6697/#postgresql , he goes on to say感谢 RhodiumToad 在ircs://irc.libera.chat:6697/#postgresql ,他继续说

configure tests whether -Wno-declaration-after-statement works and sets up that variable accordingly well actually I think it checks for -Wdeclaration-after-statement and if that works, assumes -Wno-... works too you can put that rule after including $(PGXS) , so you can make it conditional on $(MAJORVERSION) if need be or conditional on PERMIT_DECLARATION_AFTER_STATEMENT being defined配置测试-Wno-declaration-after-statement有效并相应地设置该变量实际上我认为它会检查-Wdeclaration-after-statement ,如果有效,则假设 -Wno-... 也有效,您可以放置该规则在包含$(PGXS) ,如果需要或以定义PERMIT_DECLARATION_AFTER_STATEMENT为条件,您可以使其以$(MAJORVERSION)为条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM