google / guetzli

Perceptual JPEG encoder
Apache License 2.0
12.9k stars 976 forks source link

Build static binary #146

Open JoyceBabu opened 7 years ago

JoyceBabu commented 7 years ago

How can I build a static binary executable?

I tried using LDFLAGS=-static and it is failing with the following error

Linking guetzli /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-png.o): In function png_reset_crc': (.text+0x1ab): undefined reference tocrc32' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-png.o): In function png_calculate_crc': (.text+0x1e9): undefined reference tocrc32' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-png.o): In function png_reset_zstream': (.text+0xb9d): undefined reference toinflateReset' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngread.o): In function png_create_read_struct_2': (.text+0x8aa): undefined reference toinflateInit_' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngread.o): In function png_read_init_3': (.text+0xb6c): undefined reference toinflateInit_' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngread.o): In function png_read_row': (.text+0xfd3): undefined reference toinflate' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngread.o): In function png_read_destroy': (.text+0x1c7b): undefined reference toinflateEnd' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngrutil.o): In function png_inflate': (.text+0x5e): undefined reference toinflate' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngrutil.o): In function png_inflate': (.text+0xca): undefined reference toinflateReset' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngrutil.o): In function png_read_finish_row': (.text+0x3ea1): undefined reference toinflate' /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libpng12.a(libpng12_la-pngrutil.o): In function png_read_finish_row': (.text+0x3ffe): undefined reference toinflateReset' collect2: error: ld returned 1 exit status guetzli.make:103: recipe for target 'bin/Release/guetzli' failed make[1]: [bin/Release/guetzli] Error 1 Makefile:34: recipe for target 'guetzli' failed make: [guetzli] Error 2

JoyceBabu commented 7 years ago

I was able to compile it by setting LDFLAGS="-static -lz"

JoyceBabu commented 7 years ago

It is not working when I try to use it in my CI tool.

You need to pass --static to pkg-config to properly get dependencies when building static binary

pkg-config --libs --static libpng

I worked around by adding LDFLAGS="-static -lpng12 -lz -lm"

robryk commented 7 years ago

Do you want a static binary (ie. one that doesn't dynamically link in anything, not even libc) or a binary that doesn't dynamically link in libpng? If latter, then this is what you get when you compile with Bazel. Would that work for you?

kaihendry commented 7 years ago

Be good if there was simply an amd64 static binary distribution. Would make it easier to deploy in a AWS Lambda function for e.g.

JoyceBabu commented 7 years ago

@robryk I was trying to generate a static binary. I want to compile on Ubuntu and be able to use it on Ubuntu and CentOS.