[R-SIG-Win] pcre2.h not found error while building R in windows

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Mon Apr 17 09:51:52 CEST 2023


On 4/15/23 19:00, Debartha Paul wrote:
> Hi. I am Debartha Paul, a Master's student in Statistics at Presidency
> University, Kolkata, India. I was trying to build R from scratch using
> RTools as described in https://contributor.r-project.org/rdevguide/ and
> https://cran.r-project.org/bin/windows/base/howto-R-devel.html but when I
> run `make all recommended`, I get an error message as follows:
> ```
>
> grep.c:75:10: fatal error: pcre2.h: No such file or directory
>     75 | # include<pcre2.h>
>        |          ^~~~~~~~~
> compilation terminated.
> make[4]: *** [../gnuwin32/MkRules:155: grep.o] Error 1
> make[3]: *** [Makefile:129: rlibs] Error 2
> make[2]: *** [Makefile:194: ../../bin/x64/R.dll] Error 2
> make[1]: *** [Makefile:114: rbuild] Error 2
> make: *** [Makefile:17: all] Error 2
>
> ```
> I ran `pacman -Q` inside my `MSYS2 MSYS` bash but discovered that `pcre2`
> exists.
> However, upon running `pacman -Q` from RTools bash, I found that it is not
> being found, and only a subset of the original file list is available now. But
> the surprising fact (to me at least) is that when I open my RTools folder,
> where its installed, I did find the`pcre2` header file inside one of the
> folders named `x86_x64-w64-mingw32.static.posix`. More surprisingly, none
> of the header files, listed inside this folder, is being listed in `pacman
> -Q`  when I run it from inside `RTools` bash. I dived deeper and found that
> the folder that `pacman -Q` is returning from lies in `var`: another folder
> inside RTools, separate from `x86_x64-w64-mingw32.static.posix`.
>
> I brought this issue up in the recently concluded Office Hours of the
> R-Contributors Slack, but unfortunately, I couldn't get any satisfactory
> solution, nor a reason, on why this is happening.
>
> I tried `pacman -Sy pcre2` from RTools bash, and the result was that I can
> now see `pcre2` in the subset that I mentioned earlier, but still, the
> problem persists. Needless to say that I even updated both my MSYS bash
> packages and RTools bash packages using `pacman -Syuu` from both.
>
> Finally, I was using `rtools43-5493-5475.exe` and fearing that it might be
> the cause, I uninstalled and installed the latest
> version(`rtools43-5550-5548.exe`), but it didn't do anything to improve my
> output.
>
> At this point, I am confused as to why this is happening, and I would be
> glad if anyone guides me towards a solution to this problem. I am using a
> Windows 11 machine and would be happy to give further information if the
> need arises.

The official documentation for building R on Windows using Rtools can be 
found from the Rtools download page 
(https://cran.r-project.org/bin/windows/Rtools/) and is for a specific 
version of R. I would recommend you read and follow that and in case of 
any questions, you can ask on the R-package-devel mailing list (or this 
one).

If you are using R-devel, at the time of this writing, the Rtools 
version to use is Rtools43, the download page is
https://cran.r-project.org/bin/windows/Rtools/rtools43/rtools.html
and the linked documentation page is
https://cran.r-project.org/bin/windows/base/howto-R-devel.html
(below referred to as howto document)

If you are using R 4.2.x, you should use Rtools42 and the documentation 
link is
https://cran.r-project.org/bin/windows/base/howto-R-4.2.html

 From your message I assume you are using R-devel. It is important to 
use the right version of Rtools for the version of R and read the right 
documentation, but the pcre2.h issue you are running into is probably 
not specific to the version. Rtools43 consists of these parts:

1. msys2
2. toolchain+libraries built using MXE
3. some extra tools

You can use Msys2 package manager for (1) from the above, so only for 
build tools. Normally you don't need to install any Msys2 packages to 
build R packages or R itself, all necessary Msys2 packages are already 
pre-installed. But you can use it to update the (1) part (see the howto 
document). There may be pcre2 installed here, but it is _not_ the pcre2 
library that might/could be used when build R and R packages. This is 
only for tools such as "make" or "tar" which you run from the command 
line. Even though Msys2 also offers some compiler toolchains and headers 
and libraries, they are not static and they are not used with R and R 
packages. I would recommend against installing any toolchain/libraries 
for any of the Msys2 subsystems inside Rtools - it is too easy to 
accidentally mix those with (2).

(2) contains the compiler toolchain, headers and libraries and this is 
what you can see under x86_x64-w64-mingw32.static.posix. So, you would 
find pcre2.h there, as well as the library, and it will be found by the 
compilers stored also there, if you follow the howto document. You can 
find the header files simply using "find" etc, but not using pacman, 
because pacman is part of (1).

(3) you can ignore for this problem, but there are some tools outside 
x86_x64-w64-mingw32.static.posix which are not from Msys2, documented 
also in the howto document

 From what you are writing, I am not sure why pcre2.h is not found. 
Please make sure you have not installed any Msys2 compiler or libraries 
inside Rtools43 - the right ones for R are already there (e.g., if you 
installed gcc from Msys2 and ran that one, it would not find pcre2.h, 
and you could easily check using "which gcc").

Please follow the howto document exactly and if you run into the problem 
again, please describe exactly the steps you have taken to install 
Rtools43 and then inside Rtools43. Please make sure you have not set any 
PATH or other important environment variables in Windows other than 
described in the howto document (old settings could e.g. lead to running 
the wrong compiler, which would not find the header file).

Best
Tomas

>
> With thanks and regards
> Debartha Paul
> Masters Student (1st Year)
>
> Department of Statistics
> Presidency University
> Kolkata
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-windows mailing list
> R-SIG-windows using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-windows



More information about the R-SIG-windows mailing list