libpng-1.6.9 fails to compile with PGI 14.3 and 14.1

I’ve gotten the following errors when compiling libpng-1.6.9

The error occurs in pngvalid.c

pgcc -DHAVE_CONFIG_H -I.   -DNDEBUG -DpgiFortran   -Msignextend  -c -o contrib/libtests/pngvalid.o contrib/libtests/pngvalid.c
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0037-Syntax error: Recovery attempted by deleting keyword if (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-S-0025-Illegal character: '\43' (contrib/libtests/pngvalid.c: 6784)
PGC-F-0008-Error limit exceeded (contrib/libtests/pngvalid.c: 6784)
PGC/x86-64 Linux 14.3-0: compilation aborted
make[1]: *** [contrib/libtests/pngvalid.o] Error 2
make[1]: Leaving directory `/usr/local/libpng-1.6.9'
make: *** [all] Error 2

and seems to center around this line block

         that->pm->limit += pow(
#           if PNG_MAX_GAMMA_8 < 14
               (that->this.bit_depth == 16 ? 8. :
                  6. + (1<<(15-PNG_MAX_GAMMA_8)))
#           else
               8.
#           endif
               /65535, data.gamma);
      }

And “whack-a-moling” this by commenting out the # if loop will cause a similar error to happen down later in the code.

E.g.,

    that->pm->limit += pow(
#           if DIGITIZE
               1.1
#           else
               1.
#           endif
               /255, data.gamma);
      }
   }

Ideas?

Thanks
Bill

Hi Bill,

The problem is that “pow” is getting preprocessed into “__builtin_pow”. Keeping the pre-processed file (-P) shows the line gets turned into:

that -> pm -> limit += __builtin_pow ( # if 11 < 14 ( that -> this . bit_depth == 16 ? 8. : 6. + ( 1 << ( 15 - 11 ) ) ) # else 8. # endif / 65535 , image_transform_data_rgb_to_gray . gamma ) ;

Hence the syntax error with the "#"s and “if”. The fix is to add the flag “-Mnobuiltin” to CFLAGS and the generic libm pow will be used.

Hope this helps,
Mat