Home  >  Article  >  Backend Development  >  Solution to error when calling gd extension in PHP caused by libpng version problem

Solution to error when calling gd extension in PHP caused by libpng version problem

伊谢尔伦
伊谢尔伦Original
2016-11-26 14:36:052276browse

Write a script test.php to test gd, and then execute it on the command line. The error message is as follows:

php test.phplibpng warning: Application was compiled with png.h from libpng-1.5.6
libpng warning: Application is running with png.c from libpng-1.2.49
libpng error: Incompatible libpng version in application and library
[read_png_file] png_create_read_struct failed

I am very confused. When compiling gd and php, the location of png has been specified – with-png-dir=/usr /local/libpng, using 1.5.6, why does it still call the built-in libpng-1.2.49 when executing, so I deleted the system libpng-1.2.49 (because it is a test environment, I just deleted it casually, Online server respects itself), I tried to recompile php, but it couldn’t be compiled, prompt: (This is because gd is called, which causes php to not find it when compiling the gd library)

/usr/bin/ld: cannot find -lpng12
collect2: ld returned 1 exit status
make: *** [sapi/fpm/php-fpm] Error 1

I wiped it, the system will be called by default library! ! ! There are only two places to compile and call png. One is the compilation parameter of php -with-png-dir=/usr/local/libpng, and the other is the gd library, so I recompile gd and found these two lines during compilation. :

Solution to error when calling gd extension in PHP caused by libpng version problem

It turns out that in gd, the system's libpng-1.2.49 has been called. By the way, the numbers libpng12, libpng15, and libpng16 represent version numbers 1.2. There are 2 methods:

1. Delete the one that comes with the system. I think this is not reliable. I am afraid that there will be mutual dependence and sequelae.

After deletion, it will become:

checking for libpng12-config... no
checking for libpng-config... /usr/local/bin/libpng-config

2. Both versions can be retained. After compilation, modify the Makefile.

Modify the value of LIBPNG12_CONFIG around line 262 to be the same as LIBPNG_CONFIG, such as:

LIBPNG12_CONFIG = /usr/bin/libpng12-config
LIBPNG_CONFIG = /usr/local/bin/libpng-config

Change it to

LIBPNG12_CONFIG = /usr/local/bin/libpng-config
LIBPNG_CONFIG = /usr/local/bin/libpng-config

Then just make && make install and it will be OK.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn