0

I want to compile farbfeld program suite. I run make. Error:

cc -s -lpng -o png2ff png2ff.o util.o
png2ff.o: In function `main':
png2ff.c:(.text.startup+0x58): undefined reference to `png_create_read_struct'
png2ff.c:(.text.startup+0x65): undefined reference to `png_create_info_struct'
png2ff.c:(.text.startup+0xb0): undefined reference to `png_init_io'
png2ff.c:(.text.startup+0xc4): undefined reference to `png_get_valid'
png2ff.c:(.text.startup+0xd2): undefined reference to `png_set_tRNS_to_alpha'
png2ff.c:(.text.startup+0xe6): undefined reference to `png_set_add_alpha'
png2ff.c:(.text.startup+0xf0): undefined reference to `png_set_expand_gray_1_2_4_to_8'
png2ff.c:(.text.startup+0xfa): undefined reference to `png_set_gray_to_rgb'
png2ff.c:(.text.startup+0x104): undefined reference to `png_set_packing'
png2ff.c:(.text.startup+0x11a): undefined reference to `png_read_png'
png2ff.c:(.text.startup+0x129): undefined reference to `png_get_image_width'
png2ff.c:(.text.startup+0x143): undefined reference to `png_get_image_height'
png2ff.c:(.text.startup+0x167): undefined reference to `png_get_rows'
png2ff.c:(.text.startup+0x184): undefined reference to `png_get_bit_depth'
png2ff.c:(.text.startup+0x27c): undefined reference to `png_destroy_read_struct'
collect2: error: ld returned 1 exit status
Makefile:26: recipe for target 'png2ff' failed
make: *** [png2ff] Error 1

Libpng is installed:

$ sudo apt-get install libpng-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libpng-dev is already the newest version (1.6.28-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

How to fix it?

I ran sudo find -name libpng.so in root directory. The file is at /usr/lib/x86_64-linux-gnu/libpng.so. I added -L/usr/lib/x86_64-linux-gnu to LD_FLAGS in config.mk. It didn't help.

Make output with -v appended to CFLAGS in config.mk:

cc -v -std=c99 -pedantic -Wall -Wextra -Os -D_DEFAULT_SOURCE  -c -o png2ff.o png2ff.c
Using built-in specs.
COLLECT_GCC=cc
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 6.3.0-12ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.3.0 20170406 (Ubuntu 6.3.0-12ubuntu2) 
COLLECT_GCC_OPTIONS='-v' '-std=c99' '-Wpedantic' '-Wall' '-Wextra' '-Os' '-D' '_DEFAULT_SOURCE' '-c' '-o' 'png2ff.o' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/6/cc1 -quiet -v -imultiarch x86_64-linux-gnu -D _DEFAULT_SOURCE png2ff.c -quiet -dumpbase png2ff.c -mtune=generic -march=x86-64 -auxbase-strip png2ff.o -Os -Wpedantic -Wall -Wextra -std=c99 -version -fstack-protector-strong -Wformat-security -o /tmp/ccsHz9de.s
GNU C99 (Ubuntu 6.3.0-12ubuntu2) version 6.3.0 20170406 (x86_64-linux-gnu)
    compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/6/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/6/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/6/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C99 (Ubuntu 6.3.0-12ubuntu2) version 6.3.0 20170406 (x86_64-linux-gnu)
    compiled by GNU C version 6.3.0 20170406, GMP version 6.1.2, MPFR version 3.1.5, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5a80a4e17a9c5c8f646e6b274db1ec27
COLLECT_GCC_OPTIONS='-v' '-std=c99' '-Wpedantic' '-Wall' '-Wextra' '-Os' '-D' '_DEFAULT_SOURCE' '-c' '-o' 'png2ff.o' '-mtune=generic' '-march=x86-64'
 as -v --64 -o png2ff.o /tmp/ccsHz9de.s
GNU assembler version 2.28 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.28
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/6/:/usr/lib/gcc/x86_64-linux-gnu/6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/6/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/6/:/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-std=c99' '-Wpedantic' '-Wall' '-Wextra' '-Os' '-D' '_DEFAULT_SOURCE' '-c' '-o' 'png2ff.o' '-mtune=generic' '-march=x86-64'
cc -L/usr/lib/x86_64-linux-gnu -s -lpng -o png2ff png2ff.o util.o
png2ff.o: In function `main':
png2ff.c:(.text.startup+0x58): undefined reference to `png_create_read_struct'
png2ff.c:(.text.startup+0x65): undefined reference to `png_create_info_struct'
png2ff.c:(.text.startup+0xb0): undefined reference to `png_init_io'
png2ff.c:(.text.startup+0xc4): undefined reference to `png_get_valid'
png2ff.c:(.text.startup+0xd2): undefined reference to `png_set_tRNS_to_alpha'
png2ff.c:(.text.startup+0xe6): undefined reference to `png_set_add_alpha'
png2ff.c:(.text.startup+0xf0): undefined reference to `png_set_expand_gray_1_2_4_to_8'
png2ff.c:(.text.startup+0xfa): undefined reference to `png_set_gray_to_rgb'
png2ff.c:(.text.startup+0x104): undefined reference to `png_set_packing'
png2ff.c:(.text.startup+0x11a): undefined reference to `png_read_png'
png2ff.c:(.text.startup+0x129): undefined reference to `png_get_image_width'
png2ff.c:(.text.startup+0x143): undefined reference to `png_get_image_height'
png2ff.c:(.text.startup+0x167): undefined reference to `png_get_rows'
png2ff.c:(.text.startup+0x184): undefined reference to `png_get_bit_depth'
png2ff.c:(.text.startup+0x27c): undefined reference to `png_destroy_read_struct'
collect2: error: ld returned 1 exit status
Makefile:26: recipe for target 'png2ff' failed
make: *** [png2ff] Error 1

Solution: png library must be linked last;

Cause: the makefile is broken.

2
  • 1
    See Options for Linking - in particular note the sentence "It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded." May 19, 2017 at 19:39
  • 2
    I can't believe that people from suckless.org didn't make a proper makefile. I changed the order so that -lpng is last and that did the thing. Thanks, learned something new today. May 19, 2017 at 19:45

1 Answer 1

0

Your libpng is missing some symbols because it's the wrong version for this version of Farbeld.

Instead of a compilation from source you can download and install the Debian package on Ubuntu Xenial or later.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .