I have problems compiling libpng on Solaris when using gcc 5.2. It worked fine with gcc 4.9 last time when I tried (I was compiling an older version at that time though, most likely 1.60.18; I don't know how to change the version of compiler though since I have just a plain account on a machine that's maintained by someone else).
I tried to compile libpng 1.6.20 and 1.7.0beta74 on both sparc and i386, Solaris 10. All of these versions and architectures show the same symptoms:
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../libpng-1.6.20 -g -O2 -MT png.lo -MD -MP -MF .deps/png.Tpo -c ../libpng-1.6.20/png.c -fPIC -DPIC -o .libs/png.o
In file included from /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/iso/stdlib_iso.h:39:0,
from /usr/include/stdlib.h:17,
from ../libpng-1.6.20/pngpriv.h:42,
from ../libpng-1.6.20/png.c:14:
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/sys/feature_tests.h:346:2: error: #error "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
^
*** Error code 1
make: Fatal error: Command failed for target `png.lo'
The relevant chunk of code that throws the error is:
/*
* It is invalid to compile an XPG3, XPG4, XPG4v2, or XPG5 application
* using c99. The same is true for POSIX.1-1990, POSIX.2-1992, POSIX.1b,
* and POSIX.1c applications. Likewise, it is invalid to compile an XPG6
* or a POSIX.1-2001 application with anything other than a c99 or later
* compiler. Therefore, we force an error in both cases.
*/
#if defined(_STDC_C99) && (defined(__XOPEN_OR_POSIX) && !defined(_XPG6))
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
and pre-2001 POSIX applications"
#elif !defined(_STDC_C99) && \
(defined(__XOPEN_OR_POSIX) && defined(_XPG6))
#error "Compiler or options invalid; UNIX 03 and POSIX.1-2001 applications \
require the use of c99"
#endif
I'm confused because I don't see __STDC_C99 or __XOPEN_OR_POSIX anywhere.
Someone suggested me to try out
export CPPFLAGS="-D_XOPEN_SOURCE=600 -D__EXTENSIONS__"
and compilation indeed succeeds if I provide these flags, but I don't want to blindly add something I don't understand.
Here's a potentially related problem faced by another software (wget).
Full log:
> ../libpng-1.6.20/configure
checking for a BSD-compatible install... /opt/csw/bin/ginstall -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /opt/csw/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking dependency style of gcc... gcc3
checking build system type... sparc-sun-solaris2.10
checking host system type... sparc-sun-solaris2.10
checking for a sed that does not truncate output... /opt/csw/bin/gsed
checking for grep that handles long lines and -e... /opt/csw/bin/ggrep
checking for egrep... /opt/csw/bin/ggrep -E
checking for fgrep... /opt/csw/bin/ggrep -F
checking how to print strings... printf
checking for ld used by gcc... /usr/ccs/bin/ld
checking if the linker (/usr/ccs/bin/ld) is GNU ld... no
checking how to run the C preprocessor... gcc -E
checking for gawk... (cached) gawk
checking whether ln -s works... yes
checking whether make sets $(MAKE)... (cached) yes
checking for BSD- or MS-compatible name lister (nm)... /usr/ccs/bin/nm -p
checking the name lister (/usr/ccs/bin/nm -p) interface... BSD nm
checking the maximum length of command line arguments... 786240
checking how to convert sparc-sun-solaris2.10 file names to sparc-sun-solaris2.10 format... func_convert_file_noop
checking how to convert sparc-sun-solaris2.10 file names to toolchain format... func_convert_file_noop
checking for /usr/ccs/bin/ld option to reload object files... -r
checking for objdump... no
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/ccs/bin/nm -p output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/ccs/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... solaris2.10 ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... no
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking that AWK works... ok
checking for ANSI C header files... (cached) yes
checking for an ANSI C-conforming const... yes
checking for size_t... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for C/C++ restrict keyword... __restrict
checking for working strtod... yes
checking for memset... yes
checking for pow... no
checking for pow in -lm... yes
checking for zlibVersion in -lz... yes
checking for feenableexcept in -lm... no
checking for feenableexcept... no
checking if using Solaris linker... yes
checking if libraries can be versioned... yes
checking for symbol prefix...
configure: pkgconfig directory is ${libdir}/pkgconfig
configure: Extra options for compiler:
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating libpng.pc
config.status: creating libpng-config
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
> make
rm -f pnglibconf.c .tf[45]
gawk -f ../libpng-1.6.20/scripts/options.awk out=.tf4 version=search\
../libpng-1.6.20/pngconf.h ../libpng-1.6.20/scripts/pnglibconf.dfa\
../libpng-1.6.20/pngusr.dfa 1>&2
gawk -f ../libpng-1.6.20/scripts/options.awk out=.tf5 .tf4 1>&2
rm .tf4
mv .tf5 pnglibconf.c
rm -f pnglibconf.out pnglibconf.tf[12]
test -d scripts || mkdir scripts || test -d scripts
gcc -E -DHAVE_CONFIG_H -I. -I../libpng-1.6.20 \
-DPNGLIB_LIBNAME='PNG16_0' -DPNGLIB_VERSION='1.6.20' -DSYMBOL_PREFIX='' -DPNG_NO_USE_READ_MACROS -DPNG_BUILDING_SYMBOL_TABLE pnglibconf.c > pnglibconf.tf1
gawk -f "../libpng-1.6.20/scripts/dfn.awk" out="pnglibconf.tf2" pnglibconf.tf1 1>&2
rm -f pnglibconf.tf1
mv pnglibconf.tf2 pnglibconf.out
rm -f pnglibconf.h
cp pnglibconf.out pnglibconf.h
make all-am
:>pngprefix.h
depbase=`echo png.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/bash ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I../libpng-1.6.20 -g -O2 -MT png.lo -MD -MP -MF $depbase.Tpo -c -o png.lo ../libpng-1.6.20/png.c &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../libpng-1.6.20 -g -O2 -MT png.lo -MD -MP -MF .deps/png.Tpo -c ../libpng-1.6.20/png.c -fPIC -DPIC -o .libs/png.o
In file included from /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/iso/stdlib_iso.h:39:0,
from /usr/include/stdlib.h:17,
from ../libpng-1.6.20/pngpriv.h:42,
from ../libpng-1.6.20/png.c:14:
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/sys/feature_tests.h:346:2: error: #error "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
^
*** Error code 1
make: Fatal error: Command failed for target `png.lo'
Current working directory /home/mojca/app/libpng/libpng-1.6.20-build2
*** Error code 1
make: Fatal error: Command failed for target `all'
I don't have gcc-5.2 but have recently built libpng-1.6.21beta02 on a sparc running SunOs-5.11 with gcc-5.1.0, and didn't see any problems.
Last edit: Glenn Randers-Pehrson 2015-12-21
I just checked and the sources (libpng version 1.6.20) compile just fine on Solaris 5.11 (again using gcc 5.2). So it's probably just OS version 5.10 that's problematic.
But then again
make testfails on Sparc 5.11:So I also checked "make test" after using
-D_XOPEN_SOURCE=600 -D__EXTENSIONS__on 5.10 and the situation there is actually worse. This is the list on Sparc:On i386
pngvalid-transformpasses, the other 8 fail.The pngstest script was fixed in libpng-1.7.0beta73 and 1.6.21beta01. The pngvalid-transform test was also fixed, in libpng 1.7.0beta74 and 1.6.21beta03.
Oh, thanks. I checked 1.7.0beta74 and all the tests pass indeed (I only tested 5.10 i386 though, but I believe your claim about the rest).
But what about the original issue? Do you have any suggestion about what I could try?
Here's a minimal example that fails to compile on Solaris 10:
If I remove
#define _POSIX_SOURCE 1from three files (pngpriv.h,pngtest.c,contrib/libtests/pngvalid.c), compilation succeeds.It seems that any code with
_POSIX_SOURCEdefined will almost always failwith GCC 5.x unless one of these three variables is defined:
_XPG6_XOPEN_SOURCE = 600_POSIX_C_SOURCE = 200112LSee also:
Here's some code from
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.2.0/include-fixed/sys/feature_tests.h:Last edit: Mojca Miklavec 2016-01-19
I created a pull request to add -std=gnu89 for gcc if needed to downgrade the new default. The respective change is in the GCC 5 changelog:
"The default mode for C is now -std=gnu11 instead of -std=gnu89."The pull request can be found here
Last edit: Dagobert Michelsen 2016-03-14
I've pulled Dagobert's patch into the libpng16 branch, then reformatted the indentation for easier reading. Thanks.
Thank you. Can this also go to the master/libpng17 branch?
Yes, I'll patch libpng17 as well. But now I'm just waiting a little while for any feedback about the libpng16 patch. I tested on several platforms at my disposal, including one running SunOS/gcc-5.1.0, and it seems OK.
OK, thank you. That makes sense.
The patch has been included in TeX Live that is being tested with the following platforms (about 20 of them):
http://tug.org/svn/texlive/trunk/Master/bin/
All of them are being tested right now (manually by various people). I will let you know in case that any builds result in problems, but it looks unlikely.
I have hit one interesting problem in TeX Live (I tried to set
export CPPFLAGS=-D_XOPEN_SOURCE=600) and ran into an opposite problem, but that flag works in stock libpng, so I would blame TeX Live's configuration for the flaw.Just curious: where does the first line from the following output come from? I see it in configure, but I don't know which autoconfig file adds it.
If a new release (with that patch) is planned before the 4th of May it would be helpful to know so that we could plan its inclusion accordingly.
Thank you, Mojca
Last edit: Mojca Miklavec 2016-03-29