pgsphere icon indicating copy to clipboard operation
pgsphere copied to clipboard

ISO C90 forbids variable length array ‘arr’ [-Werror=vla]

Open joelonsql opened this issue 3 years ago • 10 comments

Build fails on Ubuntu 20.04.2 LTS running Ubuntu 13.2-1.pgdg20.04+1:

polygon.c: In function ‘spherepoly_in’:
polygon.c:827:3: error: ISO C90 forbids variable length array ‘arr’ [-Werror=vla]
  827 |   SPoint  arr[nelem];
      |   ^~~~~~
polygon.c: In function ‘spherepoly_area’:
polygon.c:895:2: error: ISO C90 forbids variable length array ‘s’ [-Werror=vla]
  895 |  SPoint  s[poly->npts + 2];
      |  ^~~~~~
cc1: some warnings being treated as errors
make: *** [<builtin>: polygon.o] Error 1

joelonsql avatar Apr 26 '21 19:04 joelonsql

I’m not affiliated with the pgsphere team. I just happen to watch this repo.

Anyway, I just wanted to suggest that you try adding -std=c99 to the compilation command for this file or use /usr/bin/c99 instead of gcc.

By the way, there’s also a pgsphere/pgsphere repo. I’m not sure which repo is the best one to open issues with these days, but that repo has shown some activity recently.

esabol avatar Apr 27 '21 00:04 esabol

I’m not affiliated with the pgsphere team. I just happen to watch this repo.

Anyway, I just wanted to suggest that you try adding -std=c99 to the compilation command for this file or use /usr/bin/c99 instead of gcc.

By the way, there’s also a pgsphere/pgsphere repo. I’m not sure which repo is the best one to open issues with these days, but that repo has shown some activity recently.

Thanks for helping out. I'll try the pgsphere/pgsphere repo instead.

joelonsql avatar Apr 27 '21 05:04 joelonsql

@joelonsql did the @esabol 's suggestion work? How did you use it?

I'm trying to upgrade from 9.2 to 13.4 and I'm getting the same error.

thanks

carlosadean avatar Sep 22 '21 12:09 carlosadean

What have you tried exactly, @carlosadean ?

Are you asking how to add the -std=c99 flag to the compilation command?

esabol avatar Sep 22 '21 15:09 esabol

@esabol how shoud I use this flag in the compilation command?

carlosadean avatar Sep 23 '21 13:09 carlosadean

Try this:

make CC="gcc -std=c99"

If that doesn't work, replace c99 with gnu99. Please report back here whether either of those help.

esabol avatar Sep 23 '21 18:09 esabol

@esabol unfortunately the command and its parameters didn't work and the result is always the same for both.

make[1]: Entering directory `/data/PostgreSQL/13.4/src/postgresql-13.4/src/backend'
make -C catalog distprep generated-header-symlinks
make[2]: Entering directory `/data/PostgreSQL/13.4/src/postgresql-13.4/src/backend/catalog'
make[2]: Nothing to be done for `distprep'.
make[2]: Nothing to be done for `generated-header-symlinks'.
make[2]: Leaving directory `/data/PostgreSQL/13.4/src/postgresql-13.4/src/backend/catalog'
make -C utils distprep generated-header-symlinks
make[2]: Entering directory `/data/PostgreSQL/13.4/src/postgresql-13.4/src/backend/utils'
make[2]: Nothing to be done for `distprep'.
make[2]: Nothing to be done for `generated-header-symlinks'.
make[2]: Leaving directory `/data/PostgreSQL/13.4/src/postgresql-13.4/src/backend/utils'
make[1]: Leaving directory `/data/PostgreSQL/13.4/src/postgresql-13.4/src/backend'
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o sscan.o sscan.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o sparse.o sparse.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o sbuffer.o sbuffer.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o vector3d.o vector3d.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o point.o point.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o euler.o euler.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o circle.o circle.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o line.o line.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o ellipse.o ellipse.c
gcc -std=c99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o polygon.o polygon.c
polygon.c: In function ‘spherepoly_in’:
polygon.c:827:3: error: variable length array ‘arr’ is used [-Werror=vla]
   SPoint  arr[nelem];
   ^
polygon.c: In function ‘spherepoly_area’:
polygon.c:895:2: error: variable length array ‘s’ is used [-Werror=vla]
  SPoint  s[poly->npts + 2];
  ^
cc1: some warnings being treated as errors
make: *** [polygon.o] Error 1

carlosadean avatar Sep 29 '21 13:09 carlosadean

I just noticed that the directory in which you are compiling polygon.c is /data/PostgreSQL/13.4/src/postgresql-13.4/src/backend. That looks like you put the pgsphere source code in the same directory as the source code for PostgreSQL. If that's the case, then that's wrong, I think. I put the pgsphere directory in my PostgreSQL contrib directory, like this: /path/to/src/postgresql-x.y/contrib/pgsphere-a.b.c/.

Compiling the source code in the correct location still won't solve the compilation error you are seeing, I think. Two possible solutions:

  1. You need to remove -Werror=vla from the compilation command. Try executing either of the following commands:
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE   -c -o polygon.o polygon.c && make

Or maybe this:

make CC="gcc -std=gnu99" CFLAGS="-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fPIC -I. -I. -I/data/PostgreSQL/13.4/src/postgresql-13.4/src/include  -D_GNU_SOURCE"
  1. There's a pull request to change the source code to get this to compile with -Werror=vla, and you can find the patch here:

https://github.com/akorotkov/pgsphere/pull/14/files

Hope this helps!

esabol avatar Oct 01 '21 17:10 esabol

Hi,

not sure if this is useful but we have made a docker container for postgres 14, using the fix from https://github.com/mdgomes/pgsphere. It also includes the pg_healpix extension.

You will find instructions here.

Cheers, Sotiria

SFotopoulou avatar Nov 09 '21 18:11 SFotopoulou

Hi,

some further information, that might be useful.

pgSphere is maintained at postgrespro repo.

It should work on PostgreSQL 10+ directly.

molinaro-m avatar Aug 24 '23 06:08 molinaro-m