-1

Im trying to compile source code, but receive: undefined reference topng_read_info' File header: #include "PngImage.hh"

#include <png.h>

#include <cstdio>
#include <csetjmp>
#include <cstring>

My compiler settings: -I/usr/include/libxml2 -I/usr/include/osmpbf -O0 -g3 -Wall -c -fmessage-length=0 -lpng

What I`m doing wrong ?

Update: I`m trying linking: -I/usr/include/libxml2 -I/usr/include/osmpbf -O0 -g3 -Wall -c -fmessage-length=0 -L/usr/include/libpng -lpng

Library libpng already installed. Nothing change I receive again: undefined reference topng_read_info

Fixed. My great mistake. I set compiler settings in eclipse instead of linker settings. Thank all for answers

native1989
  • 95
  • 2
  • 10

2 Answers2

4

You are not linking against libpng. Add -L/path/to/dir_containing/libpng -lpng to your link step.

greg
  • 4,519
  • 27
  • 44
  • I`m trying linking: -I/usr/include/libxml2 -I/usr/include/osmpbf -O0 -g3 -Wall -c -fmessage-length=0 -L/usr/include/libpng -lpng Library libpng already installed. Nothing change I receive again: undefined reference topng_read_info – native1989 May 03 '12 at 06:20
  • You said `-L/usr/include/libpng`. These are the header files. You want to use `-I` instead of `-L` for include paths (`-I/usr/include/libpng` assuming that directory contains `png.h`). You still need to use a `-L` for the directory that contains `libpng.so` (or `libpng.a`, `libpng.dll`, etc.) and then `-lpng` to link in the library. `-L` says where to look for libraries to link, `-l` is a library to link. – greg May 03 '12 at 12:54
0

you get "undefined reference to" issue when the compiler cant find the link to an object so you miss an include or setting library path so try what greg said and check if you miss some include

Oumaya
  • 645
  • 3
  • 17
  • 40