不带 -Wdeclaration-after-statement 的 PostgreSQL C 扩展
PostgreSQL C Extensions without -Wdeclaration-after-statement
目前,当我编译我的扩展时,我得到,
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
57 | uint32 n = fctx->n;
PostgreSQL 当前在编译期间使用 -Wdeclaration-after-statement
。他们在我机器上的 pgxs
全局 make 文件中专门设置了这个选项,该文件位于
/usr/lib/postgresql/13/lib/pgxs/src/Makefile.global
是用他们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
是否可以禁用 -Wdeclaration-after-statement
或者每个 PostgreSQL 扩展作者都必须采用相同的约定?我可以在我的扩展中覆盖 CFLAGS 吗?
您可能可以按照 link
中描述的说明覆盖它
变量PG_CFLAGS
会附加到CFLAGS
,所以只需要加上-Wno-declaration-after-statement
我能够通过结束我的扩展程序的 Makefile
来消除这些警告,例如,
PG_CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
include $(PGXS)
RhodiumToad 在 include $(PGXS)
之后提供了另一种方法
include $(PGXS)
$(OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
感谢 ircs://irc.libera.chat:6697/#postgresql
上的 RhodiumToad,他接着说
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
目前,当我编译我的扩展时,我得到,
warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
57 | uint32 n = fctx->n;
PostgreSQL 当前在编译期间使用 -Wdeclaration-after-statement
。他们在我机器上的 pgxs
全局 make 文件中专门设置了这个选项,该文件位于
/usr/lib/postgresql/13/lib/pgxs/src/Makefile.global
是用他们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
是否可以禁用 -Wdeclaration-after-statement
或者每个 PostgreSQL 扩展作者都必须采用相同的约定?我可以在我的扩展中覆盖 CFLAGS 吗?
您可能可以按照 link
中描述的说明覆盖它变量PG_CFLAGS
会附加到CFLAGS
,所以只需要加上-Wno-declaration-after-statement
我能够通过结束我的扩展程序的 Makefile
来消除这些警告,例如,
PG_CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
include $(PGXS)
RhodiumToad 在 include $(PGXS)
include $(PGXS)
$(OBJS): CFLAGS += $(PERMIT_DECLARATION_AFTER_STATEMENT)
感谢 ircs://irc.libera.chat:6697/#postgresql
上的 RhodiumToad,他接着说
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 onPERMIT_DECLARATION_AFTER_STATEMENT
being defined