Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with static build (Amazon Linux) (still requires libgd.so.2) #86

Open
ffxsam opened this issue Mar 20, 2019 · 11 comments
Open

Issues with static build (Amazon Linux) (still requires libgd.so.2) #86

ffxsam opened this issue Mar 20, 2019 · 11 comments

Comments

@ffxsam
Copy link

ffxsam commented Mar 20, 2019

This was not straight-forward and unfortunately required a lot of manual builds of libraries (Amazon's fault). The last one I'm stuck on is libgd. Despite using BUILD_STATIC=1 in the cmake step, audiowaveform still requires libgd.so.2 when I run it. This is the only library that wasn't built into the executable for some reason.

Anyone have any ideas on how to resolve this?

@ffxsam
Copy link
Author

ffxsam commented Mar 20, 2019

If I remove gd-devel entirely and build it myself configure --enable-static --disable-shared then make, I get a libgd.a file that I put in /usr/lib64. I also copy the *.h files into /usr/include. Then in the audiowaveform folder I run cmake -D ENABLE_TESTS=0 BUILD_STATIC=1 .. and that works fine. Finally, I run make and get:

[100%] Building C object CMakeFiles/audiowaveform.dir/src/madlld-1.1p1/bstdfile.c.o
Linking CXX executable audiowaveform
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/../../../../lib64/libgd.a(gd_png.o): In function `gdPngReadData':
/home/ec2-user/libgd/src/gd_png.c:86: undefined reference to `png_get_io_ptr'
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/../../../../lib64/libgd.a(gd_png.o): In function `gdPngErrorHandler':
gd_png.c:(.text+0x6c): undefined reference to `png_get_error_ptr'
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/../../../../lib64/libgd.a(gd_png.o): In function `_gdImagePngCtxEx':
gd_png.c:(.text+0x113): undefined reference to `png_create_write_struct'
gd_png.c:(.text+0x129): undefined reference to `png_create_info_struct'
gd_png.c:(.text+0x167): undefined reference to `png_set_write_fn'
gd_png.c:(.text+0x175): undefined reference to `png_set_compression_level'
gd_png.c:(.text+0x1dd): undefined reference to `png_set_pHYs'
gd_png.c:(.text+0x2e7): undefined reference to `png_set_IHDR'
gd_png.c:(.text+0x347): undefined reference to `png_destroy_write_struct'
gd_png.c:(.text+0x39d): undefined reference to `png_set_IHDR'
gd_png.c:(.text+0x3e1): undefined reference to `png_write_info'
gd_png.c:(.text+0x3eb): undefined reference to `png_set_packing'
gd_png.c:(.text+0x446): undefined reference to `png_destroy_write_struct'
gd_png.c:(.text+0x465): undefined reference to `png_set_IHDR'
gd_png.c:(.text+0x4d2): undefined reference to `png_set_tRNS'
gd_png.c:(.text+0x5ce): undefined reference to `png_destroy_write_struct'
gd_png.c:(.text+0x6df): undefined reference to `png_write_image'
gd_png.c:(.text+0x6ee): undefined reference to `png_write_end'
gd_png.c:(.text+0x730): undefined reference to `png_write_image'
gd_png.c:(.text+0x73f): undefined reference to `png_write_end'
gd_png.c:(.text+0x754): undefined reference to `png_set_tRNS'
gd_png.c:(.text+0x7f3): undefined reference to `png_set_PLTE'
gd_png.c:(.text+0x9a0): undefined reference to `png_write_image'
gd_png.c:(.text+0x9af): undefined reference to `png_write_end'
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/../../../../lib64/libgd.a(gd_png.o): In function `gdPngWriteData':
gd_png.c:(.text+0xaad): undefined reference to `png_get_io_ptr'
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/../../../../lib64/libgd.a(gd_png.o): In function `gdImageCreateFromPngCtx':
gd_png.c:(.text+0xb47): undefined reference to `png_sig_cmp'
gd_png.c:(.text+0xb64): undefined reference to `png_create_read_struct'
gd_png.c:(.text+0xb76): undefined reference to `png_create_info_struct'
gd_png.c:(.text+0xbb2): undefined reference to `png_destroy_read_struct'
gd_png.c:(.text+0xbeb): undefined reference to `png_set_sig_bytes'
gd_png.c:(.text+0xbff): undefined reference to `png_set_read_fn'
gd_png.c:(.text+0xc0e): undefined reference to `png_read_info'
gd_png.c:(.text+0xc48): undefined reference to `png_get_IHDR'
gd_png.c:(.text+0xccf): undefined reference to `png_destroy_read_struct'
gd_png.c:(.text+0xd54): undefined reference to `png_destroy_read_struct'
gd_png.c:(.text+0xd70): undefined reference to `png_get_valid'
gd_png.c:(.text+0xdb6): undefined reference to `png_set_gray_to_rgb'
gd_png.c:(.text+0xdca): undefined reference to `png_get_valid'
gd_png.c:(.text+0xde2): undefined reference to `png_read_update_info'
gd_png.c:(.text+0xdf1): undefined reference to `png_get_rowbytes'
gd_png.c:(.text+0xeb3): undefined reference to `png_read_image'
gd_png.c:(.text+0xebf): undefined reference to `png_read_end'
gd_png.c:(.text+0xf98): undefined reference to `png_destroy_read_struct'
gd_png.c:(.text+0x10b8): undefined reference to `png_get_valid'
gd_png.c:(.text+0x10dc): undefined reference to `png_get_tRNS'
gd_png.c:(.text+0x1128): undefined reference to `png_get_PLTE'
gd_png.c:(.text+0x113c): undefined reference to `png_get_valid'
gd_png.c:(.text+0x1164): undefined reference to `png_get_tRNS'
gd_png.c:(.text+0x11fe): undefined reference to `png_set_packing'
gd_png.c:(.text+0x122e): undefined reference to `png_set_strip_16'
gd_png.c:(.text+0x125d): undefined reference to `png_get_pHYs'
gd_png.c:(.text+0x12fd): undefined reference to `png_get_tRNS'
/usr/lib/gcc/x86_64-amazon-linux/4.8.5/../../../../lib64/libgd.a(gd_png.o): In function `gdPngReadData':
gd_png.c:(.text+0x40): undefined reference to `png_error'
collect2: error: ld returned 1 exit status
make[2]: *** [audiowaveform] Error 1
make[1]: *** [CMakeFiles/audiowaveform.dir/all] Error 2
make: *** [all] Error 2

@ajbarber
Copy link

ajbarber commented Mar 20, 2019

@ffxsam, do a ldd audiowaveform to see what is still being dynamically linked to your binary. It should link the c and c++ libraries only. I suspect your problems are with libpng not libgd....

@ffxsam
Copy link
Author

ffxsam commented Mar 20, 2019

@ajbarber I can't build a static binary (see above). The make step fails. If I install gd and gd-devel, then it builds ok, but it relies on libgd.so.2: (this is after I remove the gd libraries again)

	linux-vdso.so.1 =>  (0x00007ffffc175000)
	libgd.so.2 => not found
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fc061dcf000)
	libm.so.6 => /lib64/libm.so.6 (0x00007fc061acd000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fc0618b7000)
	libc.so.6 => /lib64/libc.so.6 (0x00007fc0614ea000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc0620d3000)

@ffxsam
Copy link
Author

ffxsam commented Mar 20, 2019

Here's the ldd output when the gd libraries are installed:

	linux-vdso.so.1 =>  (0x00007ffd5c71f000)
	libgd.so.2 => /usr/lib64/libgd.so.2 (0x00007f197e380000)
	libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f197e07c000)
	libm.so.6 => /lib64/libm.so.6 (0x00007f197dd7a000)
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f197db64000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f197d797000)
	libXpm.so.4 => /usr/lib64/libXpm.so.4 (0x00007f197d586000)
	libX11.so.6 => /usr/lib64/libX11.so.6 (0x00007f197d24b000)
	libjpeg.so.62 => /usr/lib64/libjpeg.so.62 (0x00007f197cff8000)
	libfontconfig.so.1 => /usr/lib64/libfontconfig.so.1 (0x00007f197cdc3000)
	libfreetype.so.6 => /usr/lib64/libfreetype.so.6 (0x00007f197cb27000)
	libpng12.so.0 => /usr/lib64/libpng12.so.0 (0x00007f197c901000)
	libz.so.1 => /lib64/libz.so.1 (0x00007f197c6eb000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f197e5c6000)
	libxcb.so.1 => /usr/lib64/libxcb.so.1 (0x00007f197c4cd000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f197c2c9000)
	libexpat.so.1 => /lib64/libexpat.so.1 (0x00007f197c0a0000)
	libXau.so.6 => /usr/lib64/libXau.so.6 (0x00007f197be9d000)

@ffxsam
Copy link
Author

ffxsam commented Apr 5, 2019

@ajbarber Hi Adam, just wondering if you're able to help. I can offer compensation for your help/time, as well.

@ffxsam
Copy link
Author

ffxsam commented Apr 5, 2019

Got it! I had my cmake command wrong. Instead of cmake -D ENABLE_TESTS=0 BUILD_STATIC=1 .., I did cmake -D ENABLE_TESTS=0 -D BUILD_STATIC=1 .. and it resulted in a makefile that properly built the binary. Dumb mistake.

@hkjasf687261gh
Copy link

hkjasf687261gh commented Apr 23, 2019

@ffxsam I'm also having issues with the static builds for this for amazon linux, as i want to use it in a lambda. Are you able to share your static builds?

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libogg.a(framing.o): relocation R_X86_64_PC32 against symbol `memmove@@GLIBC_2.2.5' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/8/../../../x86_64-linux-gnu/libogg.a(bitwise.o): relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/audiowaveform_tests.dir/build.make:616: audiowaveform_tests] Error 1
make[1]: *** [CMakeFiles/Makefile2:105: CMakeFiles/audiowaveform_tests.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

@ffxsam
Copy link
Author

ffxsam commented Apr 23, 2019

@hkjasf687261gh Happy to share. It was a total pain to build, honestly, and I hope I never have to do it again. 😅

audiowaveform.zip

@raedatoui
Copy link

@ffxsam any chance you can share your build script?

@ffxsam
Copy link
Author

ffxsam commented Oct 30, 2019

@raedatoui Unfortunately it's not that simple and clean. It was a massive headache finding and installing all kinds of libraries. So I don't have a simple script that built everything and resulted in a single binary.

@electricazimuth
Copy link

For future me's needing a static binary for AWS - I just sent in a pull request with a Dockerfile that'll build one for you. Available here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants