Menu

#73 Makefile-nolib fails linking with missing libpng symbols

None
open
None
1
2016-10-03
2016-10-01
No
gcc  -o pngcrush pngcrush.o -L/sw/lib -L/usr/lib -lpng -lz -lm
Undefined symbols for architecture x86_64:
  "_png_crc_finish", referenced from:
      _pngcrush_measure_idat in pngcrush.o
  "_png_crc_read", referenced from:
      _pngcrush_measure_idat in pngcrush.o
  "_png_read_transform_info", referenced from:
      _main in pngcrush.o
  "_png_reset_crc", referenced from:
      _pngcrush_measure_idat in pngcrush.o
ld: symbol(s) not found for architecture x86_64

When linking pngcrush, the above symbols are not found. libpng16.dylib is in /sw/lib, and those four symbols are marked as local (non-external) in the library.

Building pngcrush with the bundled zlib and libpng libraries works.

Discussion

  • Glenn Randers-Pehrson

    • assigned_to: Glenn Randers-Pehrson
    • Group: -->
     
  • Glenn Randers-Pehrson

    What version of pngcrush are you trying to build?

     
  • Hanspeter Niederstrasser

    v1.8.7 using the pngcrush-1.8.7.tar.gz tarball and make -f Makefile-nolib PNGINC=/sw/include PNGLIB=/sw/lib, but the undefined symbols error also happens with git HEAD.

     

    Last edit: Hanspeter Niederstrasser 2016-10-02
  • Glenn Randers-Pehrson

    Please try git HEAD (version 1.8.8)

     
  • Hanspeter Niederstrasser

    Same error after updating to commit a828b8ea07 (current HEAD) in git:

    gcc  -o pngcrush pngcrush.o -L/sw/lib -lpng -lz -lm
    Undefined symbols for architecture x86_64:
      "_png_crc_finish", referenced from:
          _pngcrush_measure_idat in pngcrush.o
      "_png_crc_read", referenced from:
          _pngcrush_measure_idat in pngcrush.o
      "_png_read_transform_info", referenced from:
          _main in pngcrush.o
      "_png_reset_crc", referenced from:
          _pngcrush_measure_idat in pngcrush.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
     
  • Glenn Randers-Pehrson

    Make sure you don't have png.h in the directory where you are trying to build the nolib version. You should only have

    cexcept.h  ChangeLog.html  LICENSE  Makefile  Makefile.solaris  pngcrush.c
    

    If you are in a directory that contains the libpng and zlib sources, you can build a "nolib"
    version by moving png.h out of the way:

    mv png.h png.h_embedded
    make clean
    make -f Makefile-nolib
    
     

    Last edit: Glenn Randers-Pehrson 2016-10-03
  • Glenn Randers-Pehrson

    Try the GIT HEAD again. I revised Makefile-nolib to temporarily move png.h out of the way,
    so you don't have to do it manually as I suggested in the previous comment. Just do

    make -f Makefile-nolib ...
    

    as before.

     

    Last edit: Glenn Randers-Pehrson 2016-10-03
  • Hanspeter Niederstrasser

    The mv png.h commands in Makefile-nolib allowed linking to finish successfully. But it led me try to figure out why internal-png.h was being found because I thought I was making sure that system -Iincludes came before local -Iincludes. The following patch also finishes linking, and there's no need to move files around:

    diff --git a/Makefile-nolib b/Makefile-nolib
    index 79e12a9..fcb9ce9 100644
    --- a/Makefile-nolib
    +++ b/Makefile-nolib
    @@ -21,7 +21,7 @@ CC = gcc
     LD = gcc
     RM = rm -f
    
    -CPPFLAGS = -I $(PNGINC)
    +CPPFLAGS = -I$(PNGINC)
    
     CFLAGS = -g -O3 -fomit-frame-pointer -Wall
     # [note that -Wall is a gcc-specific compilation flag ("all warnings on")]
    @@ -48,10 +48,7 @@ EXES = $(PNGCRUSH)$(E)
     all:  $(EXES)
    
     pngcrush$(O): pngcrush.c cexcept.h
    -   touch png.h
    -   mv png.h png.h_embedded
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $<
    -   mv png.h_embedded png.h
    
     $(PNGCRUSH)$(E): $(OBJS)
        $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
    diff --git a/pngcrush.c b/pngcrush.c
    index 904ea70..5c7e355 100644
    --- a/pngcrush.c
    +++ b/pngcrush.c
    @@ -336,8 +336,7 @@ Change log:
    
     Version 1.8.8 (built with libpng-1.6.26beta01 and zlib-1.2.8)
       Fixed "nolib" build (bug report by Hanspeter Niederstrasser).
    -    Moves png.h temporarily to png.h_embedded, then puts it back after
    -    compiling pngcrush.c.
    +    Make sure we use system-png.h, and not the local file.
    
     Version 1.8.7 (built with libpng-1.6.25 and zlib-1.2.8)
       Do not check the ADLER32 CRC while reading except during the final write
    @@ -1451,7 +1450,7 @@ static int verbose = 1;
     #endif
    
     #ifndef LIBPNG_UNIFIED
    -#include "png.h"
    +#include <png.h>
     #define PNGCRUSH_TIMER_UINT_API extern unsigned int PNGAPI
     #define PNGCRUSH_TIMER_VOID_API extern void PNGAPI
     #else
    

    We force finding png.h through -I includes instead of through the file system.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.