Opened 14 years ago

Closed 14 years ago

#3655 closed defect (fixed)

When building on RHEL-4 with -O3 GeoJSON fails to compile

Reported by: jhayes Owned by: warmerdam
Priority: normal Milestone: 1.7.3
Component: default Version: 1.7.2
Severity: normal Keywords:
Cc:

Description

I'm building on RHEL 4 with CFLAGS="-DNDEBUG -O3 -D_GNU_SOURCE -D_REENTRANT -D_PTHREADS".

When compiling ogr/ogrsf_frmts/geojson/jsonc/json_object.c gcc fails with the following:

json_object.c:27: error: syntax error before "extension" json_object.c:27: error: syntax error before "n" json_object.c:27: error: syntax error before "if" json_object.c:27: warning: type defaults to int' in declaration of retval' json_object.c:27: error: conflicting types for 'retval' json_object.c:27: error: previous declaration of 'retval' was here json_object.c:27: error: `len' undeclared here (not in a function) json_object.c:27: warning: initialization makes integer from pointer without a cast json_object.c:27: error: initializer element is not constant json_object.c:27: warning: data definition has no type or storage class json_object.c:27: error: syntax error before "if" json_object.c:27: warning: type defaults to int' in declaration of retval' json_object.c:27: error: redefinition of 'retval' json_object.c:27: error: previous definition of 'retval' was here json_object.c:27: error: redefinition of 'retval' json_object.c:27: error: previous definition of 'retval' was here json_object.c:27: error: syntax error before "const" json_object.c:27: warning: data definition has no type or storage class json_object.c:27: warning: type defaults to int' in declaration of retval' json_object.c:27: warning: data definition has no type or storage class json_object.c:27: error: syntax error before '}' token

After some hunting, I found the combination of -D_GNU_SOURCE and -O3 causes string.h to define strndup() as a macro. (_GNU_SOURCE adds strndup() and -03 makes a macro.)

ogr/ogrsf_frmts/geojson/jsonc/config.h is not defining HAVE_STRNDUP so jsonc define strndup() and this interacts poorly with the strndup() macro.

I've included a patch the sets HAVE_STRNDUP if _GNU_SOURCE is defined.

Attachments (1)

rhel4-geojson.patch (576 bytes ) - added by jhayes 14 years ago.

Download all attachments as: .zip

Change History (2)

by jhayes, 14 years ago

Attachment: rhel4-geojson.patch added

comment:1 by Even Rouault, 14 years ago

Milestone: 1.7.3
Resolution: fixed
Status: newclosed

Fixed in trunk (r19889) and in branches/1.7 (r19890).

(In fact, -O2 or -O3 don't turn strndup() into a macro, but they turn one of the element of the declaration in string.h into something non-empty, whereas the redefinition in json_object.c has not that extension, hence the above errors

extern char *strndup (__const char *__string, size_t __n)
     __THROW __attribute_malloc__ __nonnull ((1));

Note: See TracTickets for help on using tickets.