Hi, I distribute cwebp as part of the EWWW Image Optimizer for WordPress, and as such I generally try to provide a static binary for the widest support across varying linux distributions. I was doing some testing today with the binaries provided from the official downloads page, and noticed that you had managed to disable some dynamic links that my builds are still showing. In particular, libjpeg, libpng, and libz. So, I was wondering if anyone knew what flags were used to compile the official binaries for linux?
On Monday, March 7, 2016 at 8:14:13 PM UTC-7, James Zern wrote:Hi,
On Saturday, March 5, 2016 at 11:51:53 PM UTC-8, shane...@gmail.com wrote:Hi, I distribute cwebp as part of the EWWW Image Optimizer for WordPress, and as such I generally try to provide a static binary for the widest support across varying linux distributions. I was doing some testing today with the binaries provided from the official downloads page, and noticed that you had managed to disable some dynamic links that my builds are still showing. In particular, libjpeg, libpng, and libz. So, I was wondering if anyone knew what flags were used to compile the official binaries for linux?The binaries from the download page are built with custom builds of the libraries in the LIBRARY_PATH, mostly to enable some metadata features in libpng which are disabled by default in libpng12. You could set something similar up and do:$ LIBRARY_PATH=<local_lib_path> ./configure ...or if your distribution packages the static libraries:$ ./configure --disable-shared --disable-tiff LIBS='-Wl,-static,-lpng,-ljpeg,-lz,-Bdynamic'I left off tiff for brevity as it may have a few dependencies. You can also try -static -static-libgcc, but that may require additional system libs. The above only targets the image libs.
Ok, so I got all that to work, I had to specify the LIBPNG_CONFIG var as well though, otherwise it tried to pull in system libs (dynamically).
I wondered about the '-static -static-libgcc' flags though. I've used those in the past for other builds and passed them as LDFLAGS, but when I do that with libwebp, it won't configure.
Here's my full command:
LDFLAGS="-static -static-libgcc" LIBRARY_PATH="/opt/libs" LIBPNG_CONFIG=/opt/bin/libpng-config CFLAGS="-Os" LIBS="-Wl,-static,-lpng,-ljpeg,-lz,-Bdynamic" ./configure --disable-shared --disable-tiff --includedir=/opt/bin/include
And the results (abbreviated):
configure: error: cannot run C compiled programs.
config.log ends like so:
[...]
configure:3548: gcc -o conftest -Os -static -static-libgcc conftest.c -Wl,-static,-lpng,-ljpeg,-lz,-Bdynamic >&5
configure:3552: $? = 0
configure:3559: ./conftest
./configure: ./conftest: /usr/lib/libc.so.1: bad ELF interpreter: No such file or directory
configure:3563: $? = 126
configure:3570: error: in `/root/libwebp-0.5.0':
configure:3572: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
Any ideas?
Here's my full command:
LDFLAGS="-static -static-libgcc" LIBRARY_PATH="/opt/libs" LIBPNG_CONFIG=/opt/bin/libpng-config CFLAGS="-Os" LIBS="-Wl,-static,-lpng,-ljpeg,-lz,-Bdynamic" ./configure --disable-shared --disable-tiff --includedir=/opt/bin/includeNote the variables can be supplied as configure arguments: './configure LIBS=...'. This allows the full command to be seen in config.log.
The remaining -Bdynamic is causing this. If you want a full static build then -static -static-libgcc should be enough.
[...]
make[1]: *** [dwebp] Error 1make[1]: Leaving directory `/root/libwebp-0.5.0/examples'make: *** [all-recursive] Error 1
I don't need dwebp, only cwebp, is there a way to bypass that so I can see if cwebp will build? Or is the compiler on CentOS 5 causing some compatibility problems?
I realized I wasn't quite following your instructions very well, so I started over a bit, this time on CentOS 6, just to see if it would resolve the glibc error.I compiled zlib, libpng, and libjpeg statically, and installed in /usr/local/ which made things simpler, so I got to libwebp and ran this:./configure --disable-shared --disable-tiff CFLAGS="-Os" LDFLAGS="-static -static-libgcc" LIBS="-Wl,-static,-lpng,-ljpeg,-lz"
On Tuesday, March 8, 2016 at 8:31:19 PM UTC-8, Shane Bishop wrote:I realized I wasn't quite following your instructions very well, so I started over a bit, this time on CentOS 6, just to see if it would resolve the glibc error.I compiled zlib, libpng, and libjpeg statically, and installed in /usr/local/ which made things simpler, so I got to libwebp and ran this:./configure --disable-shared --disable-tiff CFLAGS="-Os" LDFLAGS="-static -static-libgcc" LIBS="-Wl,-static,-lpng,-ljpeg,-lz"Let's simplify this and use makefile.unix (make -f makefile.unix) instead, autoconf/libtool may be complicating things by stripping the -static from the link step.Just edit makefile.unix's EXTRA_FLAGS to include '-static -static-libgcc'; you may also need some combination of -fno-stack-protect / -D_FORTIFY_SOURCE=0 / <some other flag I'm forgetting>. EXTRA_FLAGS works for me if I remove -DWEBP_HAVE_TIFF as I didn't want to add in the rest of its dependencies.
EXTRA_FLAGS = -DWEBP_HAVE_PNG -DWEBP_HAVE_JPEG -static -static-libgcc
CWEBP_LIBS= $(DWEBP_LIBS) -ljpeg -WlConfirmed working on CentOS 5,6,7 32&64-bit, Debian 7&8, Ubuntu 12.04, 14.04 and 15.10In all, these are the lines I changed:EXTRA_FLAGS = -DWEBP_HAVE_PNG -DWEBP_HAVE_JPEG -static -static-libgcc
CWEBP_LIBS= $(DWEBP_LIBS) -ljpeg -Wl
CFLAGS = -Os -DNDEBUG $(EXTRA_FLAGS)I modified the CFLAGS from -O3 to -Os so it is optimized for smallest size, old habit, but it makes the binary much smaller usually, about 1.2 MB in this case.
Also removed -DWEBP_HAVE_TIFF as you said, and added -static and -static-libgcc to the EXTRA_FLAGS and then added '-Wl' to the CWEBP_LIBS to match what you had originally suggested for LIBS.
Thank you so much for your help!
Any idea how I can replicate this on FreeBSD? When using 'configure', I get similar errors as I had on linux, and when I try using makefile.unix, it just says "Error expanding embedded variable"I tried using bash, but that didn't change anything...
I tried one last thing last night, and that did the trick. In looking back through my notes, I realized I had issues building before on FreeBSD with the default gcc.
So I installed gcc 4.9 and used that along with gmake, and it worked. So for posterity, here is what I had to modify in makefile.unix:EXTRA_FLAGS= -DWEBP_HAVE_PNG -DWEBP_HAVE_JPEG -I/usr/local/include -static -static-libgccCC = gcc49
After that, running ldd against cwebp properly states: "not a dynamic ELF executable"
On Friday, March 11, 2016 at 5:18:23 AM UTC-8, Shane Bishop wrote:I tried one last thing last night, and that did the trick. In looking back through my notes, I realized I had issues building before on FreeBSD with the default gcc.What version of freebsd / gcc out of curiosity? There was an earlier thread with a similar problem, but that seemed to be due to an incomplete upgrade. Using the binary packages for the release worked with an older 4.2 gcc if I'm remembering correctly.