Pecl在macOS Big Sur上无法编译Imagick扩展,如何修复?

3

我尝试为 PHP 8(或 PHP 7.4)安装 Imagick 扩展,但是 PECL 无法从源代码编译 Imagick,但可以安装其他 PHP 扩展。

Xcode 已安装 - 是的
PHP 已安装 - 是的
Imagemagick 已安装 - 是的
PECL 已安装 - 是的

安装日志

workhard@mbp % pecl install imagick
downloading imagick-3.4.4.tgz ...
Starting to download imagick-3.4.4.tgz (253,434 bytes)
.....................................................done: 253,434 bytes
19 source files, building
running: phpize
Configuring for:
PHP Api Version:         20200930
Zend Module Api No:      20200930
Zend Extension Api No:   420200930
Please provide the prefix of ImageMagick installation [autodetect] : 
building in /private/tmp/pear/temp/pear-build-workhard3KXfYN/imagick-3.4.4
running: /private/tmp/pear/temp/imagick/configure --with-php-config=/usr/local/opt/php/bin/php-config --with-imagick
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-apple-darwin20.1.0
checking host system type... x86_64-apple-darwin20.1.0
checking target system type... x86_64-apple-darwin20.1.0
checking for PHP prefix... /usr/local/Cellar/php/8.0.0_1
checking for PHP includes... -I/usr/local/Cellar/php/8.0.0_1/include/php -I/usr/local/Cellar/php/8.0.0_1/include/php/main -I/usr/local/Cellar/php/8.0.0_1/include/php/TSRM -I/usr/local/Cellar/php/8.0.0_1/include/php/Zend -I/usr/local/Cellar/php/8.0.0_1/include/php/ext -I/usr/local/Cellar/php/8.0.0_1/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/Cellar/php/8.0.0_1/pecl/20200930
checking for PHP installed headers prefix... /usr/local/Cellar/php/8.0.0_1/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking whether to enable the imagick extension... yes, shared
checking for pkg-config... /usr/local/bin/pkg-config
checking ImageMagick MagickWand API configuration program... checking Testing /usr/local/bin/MagickWand-config... It exists
found in /usr/local/bin/MagickWand-config
checking if ImageMagick version is at least 6.2.4... found version 7.0.10 Q16 HDRI
checking for MagickWand.h or magick-wand.h header... /usr/local/Cellar/imagemagick/7.0.10-48/include/ImageMagick-7/MagickWand/MagickWand.h
checking PHP version is at least 5.3.2... yes. found 8.0.0
libs
-L/usr/local/Cellar/imagemagick/7.0.10-48/lib -lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI


checking for MagickGetVersion... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for ld used by cc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 786432
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fno-common
checking if cc PIC flag -fno-common works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin20.1.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/ksh /private/tmp/pear/temp/pear-build-workhard3KXfYN/imagick-3.4.4/libtool --mode=compile cc -I. -I/private/tmp/pear/temp/imagick -I/private/tmp/pear/temp/pear-build-workhard3KXfYN/imagick-3.4.4/include -I/private/tmp/pear/temp/pear-build-workhard3KXfYN/imagick-3.4.4/main -I/private/tmp/pear/temp/imagick -I/usr/local/Cellar/php/8.0.0_1/include/php -I/usr/local/Cellar/php/8.0.0_1/include/php/main -I/usr/local/Cellar/php/8.0.0_1/include/php/TSRM -I/usr/local/Cellar/php/8.0.0_1/include/php/Zend -I/usr/local/Cellar/php/8.0.0_1/include/php/ext -I/usr/local/Cellar/php/8.0.0_1/include/php/ext/date/lib -I/usr/local/Cellar/imagemagick/7.0.10-48/include/ImageMagick-7  -DHAVE_CONFIG_H  -g -O2   -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/Cellar/imagemagick/7.0.10-48/include/ImageMagick-7 -c /private/tmp/pear/temp/imagick/imagick_file.c -o imagick_file.lo
mkdir .libs
 cc -I. -I/private/tmp/pear/temp/imagick -I/private/tmp/pear/temp/pear-build-workhard3KXfYN/imagick-3.4.4/include -I/private/tmp/pear/temp/pear-build-workhard3KXfYN/imagick-3.4.4/main -I/private/tmp/pear/temp/imagick -I/usr/local/Cellar/php/8.0.0_1/include/php -I/usr/local/Cellar/php/8.0.0_1/include/php/main -I/usr/local/Cellar/php/8.0.0_1/include/php/TSRM -I/usr/local/Cellar/php/8.0.0_1/include/php/Zend -I/usr/local/Cellar/php/8.0.0_1/include/php/ext -I/usr/local/Cellar/php/8.0.0_1/include/php/ext/date/lib -I/usr/local/Cellar/imagemagick/7.0.10-48/include/ImageMagick-7 -DHAVE_CONFIG_H -g -O2 -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -Xpreprocessor -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/Cellar/imagemagick/7.0.10-48/include/ImageMagick-7 -c /private/tmp/pear/temp/imagick/imagick_file.c  -fno-common -DPIC -o .libs/imagick_file.o
In file included from /private/tmp/pear/temp/imagick/imagick_file.c:22:
/private/tmp/pear/temp/imagick/php_imagick_file.h:61:108: error: expected ')'
zend_bool php_imagick_file_init(struct php_imagick_file_t *file, const char *filename, size_t filename_len TSRMLS_DC);
                                                                                                           ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:61:32: note: to match this '('
zend_bool php_imagick_file_init(struct php_imagick_file_t *file, const char *filename, size_t filename_len TSRMLS_DC);
                               ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:65:54: error: expected ')'
int php_imagick_safe_mode_check(const char *filename TSRMLS_DC);
                                                     ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:65:32: note: to match this '('
int php_imagick_safe_mode_check(const char *filename TSRMLS_DC);
                               ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:68:134: error: expected ')'
php_imagick_rw_result_t php_imagick_read_file(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC);
                                                                                                                                     ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:68:46: note: to match this '('
php_imagick_rw_result_t php_imagick_read_file(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC);
                                             ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:71:153: error: expected ')'
php_imagick_rw_result_t php_imagick_write_file(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type, zend_bool adjoin TSRMLS_DC);
                                                                                                                                                        ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:71:47: note: to match this '('
php_imagick_rw_result_t php_imagick_write_file(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type, zend_bool adjoin TSRMLS_DC);
                                              ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:74:112: error: expected ')'
zend_bool php_imagick_stream_handler(php_imagick_object *intern, php_stream *stream, ImagickOperationType type TSRMLS_DC);
                                                                                                               ^
/private/tmp/pear/temp/imagick/php_imagick_file.h:74:37: note: to match this '('
zend_bool php_imagick_stream_handler(php_imagick_object *intern, php_stream *stream, ImagickOperationType type TSRMLS_DC);
                                    ^
/private/tmp/pear/temp/imagick/imagick_file.c:81:51: error: expected ')'
zend_bool php_imagick_is_url(const char *filename TSRMLS_DC)
                                                  ^
/private/tmp/pear/temp/imagick/imagick_file.c:81:29: note: to match this '('
zend_bool php_imagick_is_url(const char *filename TSRMLS_DC)
                            ^
/private/tmp/pear/temp/imagick/imagick_file.c:85:90: error: expected ')'
        if (php_stream_locate_url_wrapper(filename, &path_for_open, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC)) {
                                                                                                ^
/private/tmp/pear/temp/imagick/imagick_file.c:85:35: note: to match this '('
        if (php_stream_locate_url_wrapper(filename, &path_for_open, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC)) {
                                         ^
/private/tmp/pear/temp/imagick/imagick_file.c:91:108: error: expected ')'
zend_bool php_imagick_file_init(struct php_imagick_file_t *file, const char *filename, size_t filename_len TSRMLS_DC)
                                                                                                           ^
/private/tmp/pear/temp/imagick/imagick_file.c:91:32: note: to match this '('
zend_bool php_imagick_file_init(struct php_imagick_file_t *file, const char *filename, size_t filename_len TSRMLS_DC)
                               ^
/private/tmp/pear/temp/imagick/imagick_file.c:123:40: error: expected ')'
                else if (php_imagick_is_url(filename TSRMLS_CC)) {
                                                     ^
/private/tmp/pear/temp/imagick/imagick_file.c:123:30: note: to match this '('
                else if (php_imagick_is_url(filename TSRMLS_CC)) {
                                           ^
/private/tmp/pear/temp/imagick/imagick_file.c:142:53: error: expected ')'
        file->absolute_path = expand_filepath(buffer, NULL TSRMLS_CC);
                                                           ^
/private/tmp/pear/temp/imagick/imagick_file.c:142:39: note: to match this '('
        file->absolute_path = expand_filepath(buffer, NULL TSRMLS_CC);
                                             ^
/private/tmp/pear/temp/imagick/imagick_file.c:160:133: error: expected ')'
int php_imagick_read_image_using_imagemagick(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC)
                                                                                                                                    ^
/private/tmp/pear/temp/imagick/imagick_file.c:160:45: note: to match this '('
int php_imagick_read_image_using_imagemagick(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC)
                                            ^
/private/tmp/pear/temp/imagick/imagick_file.c:201:133: error: expected ')'
int php_imagick_read_image_using_php_streams(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC)
                                                                                                                                    ^
/private/tmp/pear/temp/imagick/imagick_file.c:201:45: note: to match this '('
int php_imagick_read_image_using_php_streams(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC)
                                            ^
/private/tmp/pear/temp/imagick/imagick_file.c:207:2: error: expected ')'
        IMAGICK_SET_ERROR_HANDLING_THROW;
        ^
/private/tmp/pear/temp/imagick/imagick_file.c:28:133: note: expanded from macro 'IMAGICK_SET_ERROR_HANDLING_THROW'
#  define IMAGICK_SET_ERROR_HANDLING_THROW zend_replace_error_handling(EH_THROW, php_imagick_exception_class_entry, &error_handling TSRMLS_CC)
                                                                                                                                    ^
/private/tmp/pear/temp/imagick/imagick_file.c:207:2: note: to match this '('
/private/tmp/pear/temp/imagick/imagick_file.c:28:71: note: expanded from macro 'IMAGICK_SET_ERROR_HANDLING_THROW'
#  define IMAGICK_SET_ERROR_HANDLING_THROW zend_replace_error_handling(EH_THROW, php_imagick_exception_class_entry, &error_handling TSRMLS_CC)
                                                                      ^
/private/tmp/pear/temp/imagick/imagick_file.c:216:3: error: expected ')'
                IMAGICK_RESTORE_ERROR_HANDLING;
                ^
/private/tmp/pear/temp/imagick/imagick_file.c:29:88: note: expanded from macro 'IMAGICK_RESTORE_ERROR_HANDLING'
#  define IMAGICK_RESTORE_ERROR_HANDLING   zend_restore_error_handling(&error_handling TSRMLS_CC)
                                                                                       ^
/private/tmp/pear/temp/imagick/imagick_file.c:216:3: note: to match this '('
/private/tmp/pear/temp/imagick/imagick_file.c:29:71: note: expanded from macro 'IMAGICK_RESTORE_ERROR_HANDLING'
#  define IMAGICK_RESTORE_ERROR_HANDLING   zend_restore_error_handling(&error_handling TSRMLS_CC)
                                                                      ^
/private/tmp/pear/temp/imagick/imagick_file.c:224:3: error: expected ')'
                IMAGICK_RESTORE_ERROR_HANDLING;
                ^
/private/tmp/pear/temp/imagick/imagick_file.c:29:88: note: expanded from macro 'IMAGICK_RESTORE_ERROR_HANDLING'
#  define IMAGICK_RESTORE_ERROR_HANDLING   zend_restore_error_handling(&error_handling TSRMLS_CC)
                                                                                       ^
/private/tmp/pear/temp/imagick/imagick_file.c:224:3: note: to match this '('
/private/tmp/pear/temp/imagick/imagick_file.c:29:71: note: expanded from macro 'IMAGICK_RESTORE_ERROR_HANDLING'
#  define IMAGICK_RESTORE_ERROR_HANDLING   zend_restore_error_handling(&error_handling TSRMLS_CC)
                                                                      ^
/private/tmp/pear/temp/imagick/imagick_file.c:228:2: error: expected ')'
        IMAGICK_RESTORE_ERROR_HANDLING;
        ^
/private/tmp/pear/temp/imagick/imagick_file.c:29:88: note: expanded from macro 'IMAGICK_RESTORE_ERROR_HANDLING'
#  define IMAGICK_RESTORE_ERROR_HANDLING   zend_restore_error_handling(&error_handling TSRMLS_CC)
                                                                                       ^
/private/tmp/pear/temp/imagick/imagick_file.c:228:2: note: to match this '('
/private/tmp/pear/temp/imagick/imagick_file.c:29:71: note: expanded from macro 'IMAGICK_RESTORE_ERROR_HANDLING'
#  define IMAGICK_RESTORE_ERROR_HANDLING   zend_restore_error_handling(&error_handling TSRMLS_CC)
                                                                      ^
/private/tmp/pear/temp/imagick/imagick_file.c:255:54: error: expected ')'
int php_imagick_safe_mode_check(const char *filename TSRMLS_DC)
                                                     ^
/private/tmp/pear/temp/imagick/imagick_file.c:255:32: note: to match this '('
int php_imagick_safe_mode_check(const char *filename TSRMLS_DC)
                               ^
/private/tmp/pear/temp/imagick/imagick_file.c:262:64: error: expected ')'
        if (PG(open_basedir) && php_check_open_basedir_ex(filename, 0 TSRMLS_CC)) {
                                                                      ^
/private/tmp/pear/temp/imagick/imagick_file.c:262:51: note: to match this '('
        if (PG(open_basedir) && php_check_open_basedir_ex(filename, 0 TSRMLS_CC)) {
                                                         ^
/private/tmp/pear/temp/imagick/imagick_file.c:269:134: error: expected ')'
php_imagick_rw_result_t php_imagick_read_file(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC)
                                                                                                                                     ^
/private/tmp/pear/temp/imagick/imagick_file.c:269:46: note: to match this '('
php_imagick_rw_result_t php_imagick_read_file(php_imagick_object *intern, struct php_imagick_file_t *file, ImagickOperationType type TSRMLS_DC)
                                             ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [imagick_file.lo] Error 1
ERROR: `make' failed

来自源的Imagick构建失败,出现了一些错误。

系统设置

当前PHP版本(使用7.4时pecl出现了一些错误)

php -v
PHP 8.0.0 (cli) (built: Nov 30 2020 13:51:52) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies

PECL 版本

pecl version

PEAR Version: 1.10.12
PHP Version: 8.0.0
Zend Engine Version: 4.0.0-dev
Running on: Darwin mbp 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64

Clang编译器版本

cc -v

Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin**strong text**

macOS版本

sw_vers -productVersion

11.0.1

2个回答

12

如果你已经在你的MBP上使用brew安装了PHP 8.0,你可以直接从源代码构建Imagick:

git clone https://github.com/Imagick/imagick
cd imagick
phpize && ./configure
make
make install

建立的扩展应该放在相似的目录中:

/usr/local/Cellar/php/8.0.0_1/pecl/20200930/

最后,在你的php.ini文件中添加以下内容即可启用:

extension="imagick.so"

在执行make命令后,我得到了以下信息:make: *** No targets specified and no makefile found. Stop.该软件包仅包含以下内容: -rw-r--r-- 1 manishj staff 0 Feb 17 03:18 Makefile.fragments -rw-r--r-- 1 manishj staff 0 Feb 17 03:18 Makefile.objects - Manish J
这太棒了!跳过Homebrew安装。 - ina
@ananas222 它起作用了!如果它对你有用,请接受这个答案。 - Bhargav Nanekalva

4
我今天安装了Imagick扩展。
看起来你需要使用php7.4来编译Imagick扩展。
如果你正在使用Homebrew,可以尝试brew install php@7.4brew link --overwrite php@7.4
我在运行这些命令后成功编译了Imagick扩展。

下面是我的系统信息:
PHP版本

php -v
PHP 7.4.13 (cli) (built: Nov 30 2020 14:57:43) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v2.9.6, Copyright (c) 2002-2020, by Derick Rethans
    with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies

PECL版本

pecl version

PEAR Version: 1.10.12
PHP Version: 7.4.13
Zend Engine Version: 3.4.0
Running on: Darwin Vongola-MBP.local 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64

Clang编译器版本

cc -v

Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

macOS版本

sw_vers -productVersion

11.0.1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接