pcre2.h:没有这样的文件或目录

问题描述 投票:0回答:5

我尝试在我的 Mac 机器上安装

openswoole
。我安装的时候也遇到这个问题

/usr/local/Cellar/[email protected]/7.4.29/include/php/ext/pcre/php_pcre.h:25:10: fatal error: pcre2.h: No such file or directory
 #include "pcre2.h"

我按照其他人的建议使用命令

brew install pcre
来解决此问题,但我总是得到相同的结果。我尝试打开文件夹
pcre
我只看到其中有一个
php_pcre.h
文件。

php homebrew openswoole
5个回答
41
投票

这是最简单的解决方案。我终于解决了我的问题。我使用 PHP 8.1.7 - Mac Pro 2022 - Apple Silicon (M1)

我的错误:致命错误:找不到“pcre2.h”文件

我使用的解决方案:

  1. brew install pcre2

  2. ln -s /opt/homebrew/opt/pcre2/include/pcre2.h /opt/homebrew/opt/[email protected]/include/php/ext/pcre/

    注意目标中的 PHP 版本,根据需要进行调整。 然后,重新运行失败的安装,例如apcu 或 openswoole。

  3. pecl install ...

安装成功:

希望对你有帮助:) 谢谢


4
投票

尝试:

sudo ln -s /opt/local/include/pcre.h /usr/include/       "replace your file location here"
sudo pecl install apc 

2
投票

对于 M1 MacBook,这就是我在安装 rdkafka 时修复该错误的方法。

pecl install rdkafka

错误

/Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre/php_pcre.h:23:10: fatal error: 'pcre2.h' file not found
#include "pcre2.h"
         ^~~~~~~~~

解决方案

ln -s /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre/pcre2.h

查看新链接

➜ cd /Applications/MAMP/bin/php/php8.0.8/include/php/ext/pcre
➜ ls -l
total 8
lrwxr-xr-x  1 ddhondup  admin    48 Oct  6 15:29 pcre2.h -> /opt/homebrew/Cellar/pcre2/10.40/include/pcre2.h
-rw-rw-r--  1 ddhondup  admin  3970 Oct  1  2021 php_pcre.h

添加链接后,就成功了。

Build process completed successfully
Installing '/Applications/MAMP/bin/php/php8.0.8/lib/php/extensions/no-debug-non-zts-20200930/rdkafka.so'
install ok: channel://pecl.php.net/rdkafka-6.0.3
configuration option "php_ini" is not set to php.ini location
You should add "extension=rdkafka.so" to php.ini

0
投票

对我来说,路径是不同的,我需要通过

找到它
brew --cellar

然后是上面的确切命令

 ln -s /opt/homebrew/Cellar/pcre2/10.42/include/pcre2.h /opt/homebrew/Cellar/[email protected]/8.1.20/include/php/ext/pcre/pcre2.h

所以你需要检查 pre 版本、php 版本并相应地更改路径:)


0
投票

如果您想在 Mac 上从源代码安装,您也可以这样做:

git clone [email protected]:PCRE2Project/pcre2.git
brew install autoconf automake libtool
cd pcre2
./autogen.sh

这将在 pcre2 目录中生成配置文件。然后运行

./configure --prefix=/usr                       \
            --docdir=/usr/share/doc/pcre2-10.42 \
            --enable-unicode                    \
            --enable-jit                        \
            --enable-pcre2-16                   \
            --enable-pcre2-32                   \
            --enable-pcre2grep-libz             \
            --enable-pcre2grep-libbz2           \
            --enable-pcre2test-libreadline      \
            --disable-static                    &&
make

检查它是否通过测试:

make check

最后安装:

sudo make install
© www.soinside.com 2019 - 2024. All rights reserved.