Bug #6297
closed12.4.1 command build errors on CentOS 7
100%
Description
Running build-saxonc-commands.sh
on CentOS 7 generated errors about the C version, such as:
Transform.c: In function ‘transform’:
Transform.c:33:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
for (int i = 1; i < argc; i++) {
^
Transform.c:33:3: note: use option -std=c99 or -std=gnu99 to compile your code
After adding -std=c99
to the GCC command lines, there were errors about int64_t
, such as:
In file included from ../Saxon.C.API/SaxonCGlue.c:1:0:
../Saxon.C.API/SaxonCGlue.h:92:3: error: unknown type name ‘int64_t’
int64_t value; /*!< Internal use only. The value of the parameter points
^
That was worked around by adding #include <stdint.h>
for __LINUX__
and __APPLE__
in SaxonCGlue.h
. I don't know whether #include <stdint.h>
would be necessary for __APPLE__
.
Also, it's not clear why #include <stdio.h>
is included a second time for __LINUX__
and __APPLE__
.
--- build-saxonc-commands.sh~ 2023-12-01 12:17:46.000000000 +0000
+++ build-saxonc-commands.sh 2023-12-19 08:52:51.329869064 +0000
@@ -4,15 +4,15 @@
parent_path=$( cd "$(dirname "$0")" ; pwd -P )
library_dir=${1-$(pwd -P)}/../libs/nix
#cd "$parent_path"
-gcc -m64 -fPIC -I../Saxon.C.API/graalvm -c ../Saxon.C.API/SaxonCGlue.c -o SaxonCGlue.o $1
+gcc -std=c99 -m64 -fPIC -I../Saxon.C.API/graalvm -c ../Saxon.C.API/SaxonCGlue.c -o SaxonCGlue.o $1
-gcc -m64 -fPIC -I../Saxon.C.API/graalvm Transform.c -o transform -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
+gcc -std=c99 -m64 -fPIC -I../Saxon.C.API/graalvm Transform.c -o transform -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
-gcc -m64 -fPIC -I../Saxon.C.API/graalvm Query.c -o query -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
+gcc -std=c99 -m64 -fPIC -I../Saxon.C.API/graalvm Query.c -o query -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
-gcc -m64 -fPIC -I../Saxon.C.API/graalvm Gizmo.c -o gizmo -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
+gcc -std=c99 -m64 -fPIC -I../Saxon.C.API/graalvm Gizmo.c -o gizmo -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
if [ -f Validate.c ]; then
- gcc -m64 -fPIC -I../Saxon.C.API/graalvm Validate.c -o validate -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
+ gcc -std=c99 -m64 -fPIC -I../Saxon.C.API/graalvm Validate.c -o validate -ldl -lc SaxonCGlue.o -L$library_dir -lsaxon-hec-12.4.1 $1
fi
--- SaxonCGlue.h~ 2023-12-01 12:17:48.000000000 +0000
+++ SaxonCGlue.h 2023-12-19 09:00:42.996931099 +0000
@@ -17,6 +17,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdint.h>
#else
#include <stdint.h>
#include <windows.h>
Updated by O'Neil Delpratt 12 months ago
Hi Tony,
Thanks for reporting your experience on CentOS 7. The suggested changes look good. I agree the option std c99
is best to make sure code is portable across C compilers.
Updated by O'Neil Delpratt 12 months ago
I have moved the initial declarations outside of the for loop, but wondering if we really should add in the C99 compile option. I welcome advice on this?
Updated by Tony Graham 12 months ago
Either leave it off or also add it to samples/cTests/build64-linux.sh
as insurance against getting another issue the next time that a C99-ism
leaks into your C code.
At this point, you are unlikely to find a user with a GCC version that
predates C99.
Updated by O'Neil Delpratt 7 months ago
- Status changed from New to Resolved
- % Done changed from 0 to 100
The c99 has been added into the C build script. I am marking this issue as resolved.
Updated by O'Neil Delpratt 5 months ago
- Status changed from Resolved to Closed
- Fixed in version set to 12.5
Bug fix applied in the Saxon 12.5 Maintenance release.
Please register to edit this issue