• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2    Installing libpng
3
4Contents
5
6       I. Simple installation
7      II. Rebuilding the configure scripts
8     III. Using scripts/makefile*
9      IV. Using cmake
10       V. Directory structure
11      VI. Building with project files
12     VII. Building with makefiles
13    VIII. Configuring libpng for 16-bit platforms
14      IX. Configuring for DOS
15       X. Configuring for Medium Model
16      XI. Prepending a prefix to exported symbols
17     XII. Configuring for compiler xxx:
18    XIII. Removing unwanted object code
19     XIV. Changes to the build and configuration of libpng in libpng-1.5.x
20      XV. Setjmp/longjmp issues
21     XVI. Common linking failures
22    XVII. Other sources of information about libpng
23
24I. Simple installation
25
26On Unix/Linux and similar systems, you can simply type
27
28    ./configure [--prefix=/path]
29    make check
30    make install
31
32and ignore the rest of this document.  "/path" is the path to the directory
33where you want to install the libpng "lib", "include", and "bin"
34subdirectories.
35
36If you downloaded a GIT clone, you will need to run ./autogen.sh before
37running ./configure, to create "configure" and "Makefile.in" which are
38not included in the GIT repository.
39
40Note that "configure" is only included in the "*.tar" distributions and not
41in the "*.zip" or "*.7z" distributions. If you downloaded one of those
42distributions, see "Building with project files" or "Building with makefiles",
43below.
44
45II. Rebuilding the configure scripts
46
47If configure does not work on your system, or if you have a need to
48change configure.ac or Makefile.am, and you have a reasonably
49up-to-date set of tools, running ./autogen.sh in a git clone before
50running ./configure may fix the problem.  To be really sure that you
51aren't using any of the included pre-built scripts, especially if you
52are building from a tar distribution instead of a git distribution,
53do this:
54
55    ./configure --enable-maintainer-mode
56    make maintainer-clean
57    ./autogen.sh --maintainer --clean
58    ./autogen.sh --maintainer
59    ./configure [--prefix=/path] [other options]
60    make
61    make install
62    make check
63
64III. Using scripts/makefile*
65
66Instead, you can use one of the custom-built makefiles in the
67"scripts" directory
68
69    cp scripts/pnglibconf.h.prebuilt pnglibconf.h
70    cp scripts/makefile.system makefile
71    make test
72    make install
73
74The files that are presently available in the scripts directory
75are listed and described in scripts/README.txt.
76
77Or you can use one of the "projects" in the "projects" directory.
78
79Before installing libpng, you must first install zlib, if it
80is not already on your system.  zlib can usually be found
81wherever you got libpng; otherwise go to http://zlib.net.  You can place
82zlib in the same directory as libpng or in another directory.
83
84If your system already has a preinstalled zlib you will still need
85to have access to the zlib.h and zconf.h include files that
86correspond to the version of zlib that's installed.
87
88If you wish to test with a particular zlib that is not first in the
89standard library search path, put ZLIBLIB, ZLIBINC, CPPFLAGS, LDFLAGS,
90and LD_LIBRARY_PATH in your environment before running "make test"
91or "make distcheck":
92
93    ZLIBLIB=/path/to/lib export ZLIBLIB
94    ZLIBINC=/path/to/include export ZLIBINC
95    CPPFLAGS="-I$ZLIBINC" export CPPFLAGS
96    LDFLAGS="-L$ZLIBLIB" export LDFLAGS
97    LD_LIBRARY_PATH="$ZLIBLIB:$LD_LIBRARY_PATH" export LD_LIBRARY_PATH
98
99If you are using one of the makefile scripts, put ZLIBLIB and ZLIBINC
100in your environment and type
101
102    make ZLIBLIB=$ZLIBLIB ZLIBINC=$ZLIBINC test
103
104IV. Using cmake
105
106If you want to use "cmake" (see www.cmake.org), type
107
108    cmake . -DCMAKE_INSTALL_PREFIX=/path
109    make
110    make install
111
112As when using the simple configure method described above, "/path" points to
113the installation directory where you want to put the libpng "lib", "include",
114and "bin" subdirectories.
115
116V. Directory structure
117
118You can rename the directories that you downloaded (they
119might be called "libpng-x.y.z" or "libpngNN" and "zlib-1.2.8"
120or "zlib128") so that you have directories called "zlib" and "libpng".
121
122Your directory structure should look like this:
123
124    .. (the parent directory)
125      libpng (this directory)
126          INSTALL (this file)
127          README
128          *.h, *.c  => libpng source files
129          CMakeLists.txt    =>  "cmake" script
130          configuration files:
131             configure.ac, configure, Makefile.am, Makefile.in,
132             autogen.sh, config.guess, ltmain.sh, missing, libpng.pc.in,
133             libpng-config.in, aclocal.m4, config.h.in, config.sub,
134             depcomp, install-sh, mkinstalldirs, test-pngtest.sh
135          contrib
136             arm-neon, conftest, examples, gregbook, libtests, pngminim,
137             pngminus, pngsuite, tools, visupng
138          projects
139             cbuilder5, owatcom, visualc71, vstudio, xcode
140          scripts
141             makefile.*
142             *.def (module definition files)
143             etc.
144          pngtest.png
145          etc.
146      zlib
147          README, *.h, *.c contrib, etc.
148
149If the line endings in the files look funny, you may wish to get the other
150distribution of libpng.  It is available in both tar.gz (UNIX style line
151endings) and zip (DOS style line endings) formats.
152
153VI. Building with project files
154
155If you are building libpng with MSVC, you can enter the
156libpng projects\visualc71 or vstudio directory and follow the instructions
157in README.txt.
158
159Otherwise enter the zlib directory and follow the instructions in zlib/README,
160then come back here and run "configure" or choose the appropriate
161makefile.sys in the scripts directory.
162
163VII. Building with makefiles
164
165Copy the file (or files) that you need from the
166scripts directory into this directory, for example
167
168MSDOS example:
169
170    copy scripts\makefile.msc makefile
171    copy scripts\pnglibconf.h.prebuilt pnglibconf.h
172
173UNIX example:
174
175    cp scripts/makefile.std makefile
176    cp scripts/pnglibconf.h.prebuilt pnglibconf.h
177
178Read the makefile to see if you need to change any source or
179target directories to match your preferences.
180
181Then read pnglibconf.dfa to see if you want to make any configuration
182changes.
183
184Then just run "make" which will create the libpng library in
185this directory and "make test" which will run a quick test that reads
186the "pngtest.png" file and writes a "pngout.png" file that should be
187identical to it.  Look for "9782 zero samples" in the output of the
188test.  For more confidence, you can run another test by typing
189"pngtest pngnow.png" and looking for "289 zero samples" in the output.
190Also, you can run "pngtest -m contrib/pngsuite/*.png" and compare
191your output with the result shown in contrib/pngsuite/README.
192
193Most of the makefiles will allow you to run "make install" to
194put the library in its final resting place (if you want to
195do that, run "make install" in the zlib directory first if necessary).
196Some also allow you to run "make test-installed" after you have
197run "make install".
198
199VIII. Configuring libpng for 16-bit platforms
200
201You will want to look into zconf.h to tell zlib (and thus libpng) that
202it cannot allocate more than 64K at a time.  Even if you can, the memory
203won't be accessible.  So limit zlib and libpng to 64K by defining MAXSEG_64K.
204
205IX. Configuring for DOS
206
207For DOS users who only have access to the lower 640K, you will
208have to limit zlib's memory usage via a png_set_compression_mem_level()
209call.  See zlib.h or zconf.h in the zlib library for more information.
210
211X. Configuring for Medium Model
212
213Libpng's support for medium model has been tested on most of the popular
214compilers.  Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
215defined, and FAR gets defined to far in pngconf.h, and you should be
216all set.  Everything in the library (except for zlib's structure) is
217expecting far data.  You must use the typedefs with the p or pp on
218the end for pointers (or at least look at them and be careful).  Make
219note that the rows of data are defined as png_bytepp, which is
220an "unsigned char far * far *".
221
222XI. Prepending a prefix to exported symbols
223
224Starting with libpng-1.6.0, you can configure libpng (when using the
225"configure" script) to prefix all exported symbols by means of the
226configuration option "--with-libpng-prefix=FOO_", where FOO_ can be any
227string beginning with a letter and containing only uppercase
228and lowercase letters, digits, and the underscore (i.e., a C language
229identifier).  This creates a set of macros in pnglibconf.h, so this is
230transparent to applications; their function calls get transformed by
231the macros to use the modified names.
232
233XII. Configuring for compiler xxx:
234
235All includes for libpng are in pngconf.h.  If you need to add, change
236or delete an include, this is the place to do it.
237The includes that are not needed outside libpng are placed in pngpriv.h,
238which is only used by the routines inside libpng itself.
239The files in libpng proper only include pngpriv.h and png.h, which
240in turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.
241As of libpng-1.5.0, pngpriv.h also includes three other private header
242files, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material
243that previously appeared in the public headers.
244
245XIII. Removing unwanted object code
246
247There are a bunch of #define's in pngconf.h that control what parts of
248libpng are compiled.  All the defines end in _SUPPORTED.  If you are
249never going to use a capability, you can change the #define to #undef
250before recompiling libpng and save yourself code and data space, or
251you can turn off individual capabilities with defines that begin with
252"PNG_NO_".
253
254In libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.
255
256You can also turn all of the transforms and ancillary chunk capabilities
257off en masse with compiler directives that define
258PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
259or all four, along with directives to turn on any of the capabilities that
260you do want.  The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the
261extra transformations but still leave the library fully capable of reading
262and writing PNG files with all known public chunks. Use of the
263PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
264that is incapable of reading or writing ancillary chunks.  If you are
265not using the progressive reading capability, you can turn that off
266with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
267capability, which you'll still have).
268
269All the reading and writing specific code are in separate files, so the
270linker should only grab the files it needs.  However, if you want to
271make sure, or if you are building a stand alone library, all the
272reading files start with "pngr" and all the writing files start with "pngw".
273The files that don't match either (like png.c, pngtrans.c, etc.)
274are used for both reading and writing, and always need to be included.
275The progressive reader is in pngpread.c
276
277If you are creating or distributing a dynamically linked library (a .so
278or DLL file), you should not remove or disable any parts of the library,
279as this will cause applications linked with different versions of the
280library to fail if they call functions not available in your library.
281The size of the library itself should not be an issue, because only
282those sections that are actually used will be loaded into memory.
283
284XIV. Changes to the build and configuration of libpng in libpng-1.5.x
285
286Details of internal changes to the library code can be found in the CHANGES
287file and in the GIT repository logs.  These will be of no concern to the vast
288majority of library users or builders; however, the few who configure libpng
289to a non-default feature set may need to change how this is done.
290
291There should be no need for library builders to alter build scripts if
292these use the distributed build support - configure or the makefiles -
293however, users of the makefiles may care to update their build scripts
294to build pnglibconf.h where the corresponding makefile does not do so.
295
296Building libpng with a non-default configuration has changed completely.
297The old method using pngusr.h should still work correctly even though the
298way pngusr.h is used in the build has been changed; however, library
299builders will probably want to examine the changes to take advantage of
300new capabilities and to simplify their build system.
301
302A. Specific changes to library configuration capabilities
303
304The exact mechanism used to control attributes of API functions has
305changed.  A single set of operating system independent macro definitions
306is used and operating system specific directives are defined in
307pnglibconf.h
308
309As part of this the mechanism used to choose procedure call standards on
310those systems that allow a choice has been changed.  At present this only
311affects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems
312running on Intel processors.  As before, PNGAPI is defined where required
313to control the exported API functions; however, two new macros, PNGCBAPI
314and PNGCAPI, are used instead for callback functions (PNGCBAPI) and
315(PNGCAPI) for functions that must match a C library prototype (currently
316only png_longjmp_ptr, which must match the C longjmp function.)  The new
317approach is documented in pngconf.h
318
319Despite these changes, libpng 1.5.0 only supports the native C function
320calling standard on those platforms tested so far ("__cdecl" on Microsoft
321Windows).  This is because the support requirements for alternative
322calling conventions seem to no longer exist.  Developers who find it
323necessary to set PNG_API_RULE to 1 should advise the mailing list
324(png-mng-implement) of this and library builders who use Openwatcom and
325therefore set PNG_API_RULE to 2 should also contact the mailing list.
326
327B. Changes to the configuration mechanism
328
329Prior to libpng-1.5.0 library builders who needed to configure libpng
330had either to modify the exported pngconf.h header file to add system
331specific configuration or had to write feature selection macros into
332pngusr.h and cause this to be included into pngconf.h by defining
333PNG_USER_CONFIG. The latter mechanism had the disadvantage that an
334application built without PNG_USER_CONFIG defined would see the
335unmodified, default, libpng API and thus would probably fail to link.
336
337These mechanisms still work in the configure build and in any makefile
338build that builds pnglibconf.h, although the feature selection macros
339have changed somewhat as described above.  In 1.5.0, however, pngusr.h is
340processed only once, at the time the exported header file pnglibconf.h is
341built.  pngconf.h no longer includes pngusr.h; therefore, pngusr.h is ignored
342after the build of pnglibconf.h and it is never included in an application
343build.
344
345The formerly used alternative of adding a list of feature macros to the
346CPPFLAGS setting in the build also still works; however, the macros will be
347copied to pnglibconf.h and this may produce macro redefinition warnings
348when the individual C files are compiled.
349
350All configuration now only works if pnglibconf.h is built from
351scripts/pnglibconf.dfa.  This requires the program awk.  Brian Kernighan
352(the original author of awk) maintains C source code of that awk and this
353and all known later implementations (often called by subtly different
354names - nawk and gawk for example) are adequate to build pnglibconf.h.
355The Sun Microsystems (now Oracle) program 'awk' is an earlier version
356and does not work; this may also apply to other systems that have a
357functioning awk called 'nawk'.
358
359Configuration options are now documented in scripts/pnglibconf.dfa.  This
360file also includes dependency information that ensures a configuration is
361consistent; that is, if a feature is switched off, dependent features are
362also switched off.  As a recommended alternative to using feature macros in
363pngusr.h a system builder may also define equivalent options in pngusr.dfa
364(or, indeed, any file) and add that to the configuration by setting
365DFA_XTRA to the file name.  The makefiles in contrib/pngminim illustrate
366how to do this, and also illustrate a case where pngusr.h is still required.
367
368After you have built libpng, the definitions that were recorded in
369pnglibconf.h are available to your application (pnglibconf.h is included
370in png.h and gets installed alongside png.h and pngconf.h in your
371$PREFIX/include directory).  Do not edit pnglibconf.h after you have built
372libpng, because than the settings would not accurately reflect the settings
373that were used to build libpng.
374
375XV. Setjmp/longjmp issues
376
377Libpng uses setjmp()/longjmp() for error handling.  Unfortunately setjmp()
378is known to be not thread-safe on some platforms and we don't know of
379any platform where it is guaranteed to be thread-safe.  Therefore, if
380your application is going to be using multiple threads, you should
381configure libpng with PNG_NO_SETJMP in your pngusr.dfa file, with
382-DPNG_NO_SETJMP on your compile line, or with
383
384    #undef PNG_SETJMP_SUPPORTED
385
386in your pnglibconf.h or pngusr.h.
387
388Starting with libpng-1.6.0, the library included a "simplified API".
389This requires setjmp/longjmp, so you must either build the library
390with PNG_SETJMP_SUPPORTED defined, or with PNG_SIMPLIFIED_READ_SUPPORTED
391and PNG_SIMPLIFIED_WRITE_SUPPORTED undefined.
392
393XVI. Common linking failures
394
395If your application fails to find libpng or zlib entries while linking:
396
397  Be sure "-lz" appears after "-lpng" on your linking command.
398
399  Be sure you have built libpng, zlib, and your application for the
400  same platform (e.g., 32-bit or 64-bit).
401
402  If you are using the vstudio project, observe the WARNING in
403  project/vstudio/README.txt.
404
405XVII. Other sources of information about libpng:
406
407Further information can be found in the README and libpng-manual.txt
408files, in the individual makefiles, in png.h, and the manual pages
409libpng.3 and png.5.
410
411Copyright (c) 1998-2002,2006-2016 Glenn Randers-Pehrson
412This document is released under the libpng license.
413For conditions of distribution and use, see the disclaimer
414and license in png.h.
415