Location to specify C compiler option in C extension

Started by Demitri Munaabout 8 years ago3 messagesgeneral
Jump to latest
#1Demitri Muna
postgresql@demitri.com

Hi,

I’m writing a C extension and have successfully based my Makefile on existing templates. This conveniently hides the details of the full Makefile provided by "pg_config --pgxs”. Which variable would be the appropriate one to specify the ‘-std=c99’ compiler flag? I’ve tried many and still get warnings that this flag should suppress (specifically, "ISO C90 forbids mixed declarations and code”). These are the variables I currently define:

EXTENSION
DATA
PGFILEDESC
MODULE_big
PG_CPPFLAGS (this one seemed like the right place)
SHLIB_LINK
OBJS
PG_CONFIG
PGXS

A workaround has been:

OBJS = file1.o file2.o CPPFLAGS+=-Wdeclaration-after-statement

but it’s not exactly the same thing.

Thanks,
Demitri

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Demitri Muna (#1)
Re: Location to specify C compiler option in C extension

Demitri Muna <postgresql@demitri.com> writes:

I’m writing a C extension and have successfully based my Makefile on existing templates. This conveniently hides the details of the full Makefile provided by "pg_config --pgxs”. Which variable would be the appropriate one to specify the ‘-std=c99’ compiler flag? I’ve tried many and still get warnings that this flag should suppress (specifically, "ISO C90 forbids mixed declarations and code”). These are the variables I currently define:

PG_CPPFLAGS ought to work. One point is that you need to set that before
including pgxs.mk; maybe it's an ordering problem?

regards, tom lane

#3Demitri Muna
postgresql@demitri.com
In reply to: Tom Lane (#2)
Re: Location to specify C compiler option in C extension

Hi Tom,

PG_CPPFLAGS ought to work. One point is that you need to set that before
including pgxs.mk; maybe it's an ordering problem?

On closer inspection, it was working, but the pg Makefile was specifically including “-Wdeclaration-after-statement” which I think was overriding the ‘-std=c99’ part. The line below fixed the problem.

PG_CPPFLAGS += -std=c99 -Wno-declaration-after-statement

Thanks, sorry for the noise.

Demitri