pecl install swoole 报错: fatal error: 'pcre2.h' file not found
公司有个项目用了 hyperf 框架,需要安装 swoole 扩展,我的新 m4 macbook air 尚未装过,执行 pecl install swoole
,结果报错了。
In file included from /private/tmp/pear/temp/swoole/ext-src/php_swoole.cc:26:
/opt/homebrew/Cellar/php@8.3/8.3.19_1/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found
23 | #include "pcre2.h"
| ^~~~~~~~~
1 error generated.
make: *** [ext-src/php_swoole.lo] Error 1
ERROR: `make' failed
提示缺少文件,手动安装了一下 pcre2
,发现早就装过了,看来问题是找不到,而不是没有装。
$ brew install pcre2
Warning: pcre2 10.45 is already installed and up-to-date.
To reinstall 10.45, run:
brew reinstall pcre2
问了下 ChatGPT,告诉我需要 export 两个东西:
export CPPFLAGS="-I/opt/homebrew/include -I/opt/homebrew/opt/pcre2/include"
export LDFLAGS="-L/opt/homebrew/lib -L/opt/homebrew/opt/pcre2/lib"
然后再执行 pecl install swoole
,果然成功了。
ChatGPT 牛逼。