pecl install swoole 安装出错:fatal error: pcre2.h: No such file or directory 作者: Chuwen 时间: 2023-09-19 分类: PHP,其他分类 安装错误日志: ```log In file included from /home/linuxbrew/.linuxbrew/Cellar/php@8.1/8.1.23/include/php/ext/spl/spl_iterators.h:22, from /home/linuxbrew/.linuxbrew/Cellar/php@8.1/8.1.23/include/php/ext/spl/spl_array.h:22, from /tmp/pear/temp/swoole/ext-src/swoole_coroutine.cc:27: /home/linuxbrew/.linuxbrew/Cellar/php@8.1/8.1.23/include/php/ext/pcre/php_pcre.h:23:10: fatal error: pcre2.h: No such file or directory 23 | #include "pcre2.h" | ^~~~~~~~~ compilation terminated. make: *** [Makefile:233: ext-src/swoole_coroutine.lo] Error 1 ERROR: `make' failed ``` ## 错误原因 这个错误消息表明编译或构建过程中缺少 pcre2.h 头文件,导致无法找到它。pcre2.h 是 PCRE2(Perl Compatible Regular Expressions)库的头文件,通常用于正则表达式操作。 ## 解决方案 **安装 PCRE2 库** 在 Ubuntu/Debian 上: ```shell sudo apt-get install libpcre2-dev ``` 在 CentOS/RHEL 上: ```shell sudo yum install pcre2-devel ``` 在 macOS 上,你可以使用 Homebrew 安装: ```shell brew install pcre2 ``` 最终完美解决,我这里正常安装 `swoole` 扩展 ``` Build process completed successfully Installing '/home/linuxbrew/.linuxbrew/Cellar/php@8.1/8.1.23/pecl/20210902/swoole.so' Installing '/home/linuxbrew/.linuxbrew/Cellar/php@8.1/8.1.23/include/php/ext/swoole/config.h' Installing '/home/linuxbrew/.linuxbrew/Cellar/php@8.1/8.1.23/include/php/ext/swoole/php_swoole.h' install ok: channel://pecl.php.net/swoole-5.0.3 Extension swoole enabled in php.ini ``` 标签: PHP, pecl