Help needed: Failed to build c-extension on CentOS image
prikha opened this issue · 1 comments
prikha commented
Hey folks! Thanks for the library!
May I ask for a tip on how to fix compilation errors for >v2.0.0
.
Trying to install on CentOS image but gem installation fails with for’ loop initial declarations are only allowed in C99 mode
[root@a8195195e062 /]# gem install pg_query
Fetching google-protobuf-3.17.3-x86_64-linux.gem
Successfully installed google-protobuf-3.17.3-x86_64-linux
Fetching pg_query-2.1.0.gem
Building native extensions. This could take a while...
ERROR: Error installing pg_query:
ERROR: Failed to build gem native extension.
current directory: /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query
/usr/bin/ruby -I /usr/share/rubygems -r ./siteconf20210823-16-fpv437.rb extconf.rb
creating Makefile
current directory: /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query
make "DESTDIR=" clean
rm -f
rm -f pg_query.so *.o *.bak mkmf.log .*.time
current directory: /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query
make "DESTDIR="
gcc -I. -I/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/include -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -fPIC -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -g -m64 -o /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/src_port_snprintf.o -c /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/src_port_snprintf.c
gcc -I. -I/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/include -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -fPIC -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -g -m64 -o /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/src_backend_utils_mb_mbutils.o -c /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/src_backend_utils_mb_mbutils.c
gcc -I. -I/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/include -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -fPIC -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -g -m64 -o /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/src_backend_utils_error_assert.o -c /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/src_backend_utils_error_assert.c
gcc -I. -I/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/include -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -fPIC -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -g -m64 -o /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/xxhash.o -c /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/xxhash.c
gcc -I. -I/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/include -I/usr/include -I/usr/include/ruby/backward -I/usr/include -I. -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -mtune=generic -fPIC -O3 -Wall -fno-strict-aliasing -fwrapv -fstack-protector -Wno-unused-function -Wno-unused-variable -g -m64 -o /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.o -c /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.c
In file included from /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_internal.h:6:0,
from /usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.c:2:
/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.c: In function ‘pg_query_split_with_parser’:
/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/include/nodes/pg_list.h:352:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (ForEachState cell##__state = {(lst), 0}; \
^
/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.c:184:3: note: in expansion of macro ‘foreach’
foreach (lc, parsetree_and_error.tree)
^
/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/include/nodes/pg_list.h:352:2: note: use option -std=c99 or -std=gnu99 to compile your code
for (ForEachState cell##__state = {(lst), 0}; \
^
/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.c:184:3: note: in expansion of macro ‘foreach’
foreach (lc, parsetree_and_error.tree)
^
/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.c: In function ‘pg_query_free_split_result’:
/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.c:215:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int i = 0; i < result.n_stmts; ++i)
^
make: *** [/usr/local/share/gems/gems/pg_query-2.1.0/ext/pg_query/pg_query_split.o] Error 1
make failed, exit code 2
Gem files will remain installed in /usr/local/share/gems/gems/pg_query-2.1.0 for inspection.
Results logged to /usr/local/lib64/gems/ruby/pg_query-2.1.0/gem_make.out
PS
- Tried to export
CFLAGS="$CFLAGS -std=c99"
with no luck. - Tried to pull the git repo and run
make
in there. It failed with the same error. - Tried to append
-std=c99
in theMakefile
. It failed with the same error.
lfittl commented
@prikha Thanks for the report!
Could you check whether you get the same error when you check out the C library directly (https://github.com/pganalyze/libpg_query) and run "make" there? (I assume that will work, and our problem here is that we're not passing the right flags when building inside Ruby's build system)