pcre2.h: No such file or directory

12.5k Views Asked by At

I try to install openswoole on my mac machine. I have this issue when installing it.

/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"

I used the command brew install pcre to fix this issue as others recommend, but I always get the same result. I try to open the folder pcre I only see one php_pcre.h file inside it.

5

There are 5 best solutions below

2
On BEST ANSWER

try:

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

If you want to install from source on a mac you can also do:

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

This will generate the configure file inside the pcre2 directory. Then run:

CFLAGS='-O2 -Wall' ./configure --prefix=/usr/local/                       \
            --docdir=/usr/local/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

check that it passes the tests:

make check

and finally install with:

sudo make install
5
On

Here's simplest solution. I have finally solved my problem. I used PHP 8.1.7 - Mac Pro 2022 - Apple Silicon (M1)

My errors: fatal error: 'pcre2.h' file not found

The solution that I used:

  1. brew install pcre2

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

    Beware of the PHP version in the destination, adjust as-needed. Then, re-run the installation that failed, e.g. apcu or openswoole.

  3. pecl install ...

Success Installation:

enter image description here

Hope it help you :) Thanks

0
On

for me the path was different, I needed to find it by

brew --cellar

and then exact command above

 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

so you need to check pre version, php version and change the paths accordingly :)

1
On

For M1 MacBooks, this is how I fixed that error when installing rdkafka.

pecl install rdkafka

Error

/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"
         ^~~~~~~~~

Solution

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

See the new link

➜ 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

After adding the link, it worked.

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