build RGtk2 from its source on Windows 10/11 [🇷 for BE/BA]

posted by yjlee168 Homepage – Kaohsiung, Taiwan, 2022-03-16 01:11 (743 d 19:11 ago) – Posting: # 22837
Views: 2,959

(edited by yjlee168 on 2022-03-16 20:16)

Dear bear users,

Since RGtk2 has been retired from CRAN at the end (Dec. 15) of 2021, there will be no more updated binary file available for users to install on Windows platform. On Linux & macOS, we have to install GTK+ (GTK2) compiler or development packages before installing RGtk2. Then we can easily build RGtk2 package for Linux or macOS. Luckily we can find RGtk2 binary (zip) from cran.micorsoft.com. We used to install RGtk2 from its binary. Then run library(RGtk2) in R console as the system admin. There is a pop-up dialogue as if users want to install GTK+. If yes, then it will go to download a zip file and unzip this zip file and put all files under the folder of /R/x.x.x/library/RGtk2/gtk. All files under ~/gtk are used as the runtime for GTK+. Done. However, we all know R is updated frequently. After all, we need to re-build or re-compile RGtk2 package to see if it still runs well on the newly updated R. Here is how I built RGtk2 package from its sources on Windows 10/11.

Procedures of installation an updated package Take RGtk2 as our example. When installing an updated RGtk2, R will move the original RGtk2 folder (~/library/RGtk2) under the newly created locked folder (e.g. ~/library/000RGtk2Lock) first and creates a new & empty folder (~/library/RGtk2). Meanwhile, there is a new folder 00new created under ~/library/000RGtk2Lock. Then R installs all newly built files under the folder 00new. If the installation succeeds, R will copy all files from the folder 00new to the folder of ~/library/RGtk2 and delete the folder of the locked folder. If installation fails, R will copy all files under ~/library/000RGtk2Lock/RGtk2 to ~/library/RGtk2 to restore the original RGtk2. It's a very good policy.

Steps to install x64 RGtk2 (same for cairoDevice) on x64 Windows 10/11:
  1. download and install R & RTOOLS40;
  2. download GTK+ development packages: here we have two choices. One is from here (set as #1) & the other is we just mentioned above the runtime (set as #2). The #1 is mentioned in the file INSTALL in RGtk2 source code tarball. When we browse the link. We can find there are two *.exe. I chose gtk-dev-2.12.9-win32-2.exe. The #2 (gtk+-bundle_2.22.1-20101229_win64.zip) was coded in zzz.R. I recommend that #2 should be used. When I tried to use #1 to compile RGtk2, it fails to build x386. Because I have x64 Windows 10? I don't know. Yes, it can build x64 RGtk2. However, R said the built x64 RGtk2 is not a real W32 package:confused:. Actually, I even failed to build x64 RGtk2 with #1 at the beginning until I used an install option of "--no-test-load". That is the final step to build R package in R. If it passes the package loading test, a binary zip file will be generated. If fails, R will delete all built files and restore the original package back to ~/library. The binary zip file is not generated either. The reason to use the install option of "--no-test-load" is that after building RGtk2, GTK+ runtime has not been installed yet. Thus, R treats the whole procedure as a failure. I wonder the developers might use #1 in a 32-bit machine & 32-bit (x86) Windows OS. Also, #1 cannot serve as the runtime. Do I just answer my own question mentioned in my previous post? If we use #1 to build x64 RGtk2, then we need to download #2 as GTK+ runtime when running library(RGtk2) on R console. So I chose #2 as my GTK developer's pack. The #2 is not only GTK+ development pack but also is GTK runtime.
  3. set the GTK developer's pack with #2: Unzip all files under a folder, e.g. C:\GTK and set it as the environment variable as GTK_PATH. OK, I followed the instruction. Unfortunately, I still got the errors (... cannot find glib.h...). I checked the error messages and found '... -mms-bitfields -I$C:\GTK/include/gtk-2.0 ....'. The backslash looked weired. So I used 'C:/GTK' to set GTK_PATH. Yes, bingo. I finally built x64 RGtk2 successfully. However, I still need to dwonlaod & install gtk+-bundle_2.22.1-20101229_win64.zip to ~/library/RGtk2/gtk when first time running library(RGtk2). So I took a look on source codes. Then I found that if I could set the following Windows environment variables RGtk2 will not ask if want to install GTK+ when running library(RGtk2) for the first time:
    ---
    GTK = C:\GTK
    GTK_PATH = C:/GTK
    GTK_INCL = C:\GTK\INCLUDE
    GTK_LIB = C:\GTK\LIB
    INCLUDE = %GTK_INCL%;%GTK_INCL%\GTK-2.0;%GTK_INCL%\GLIB-2.0;%GTK_INCL%\PANGO-1.0;%GTK_INCL%\CAIRO;%GTK_INCL%\ATK-1.0;%GTK_LIB%\GTK-2.0\INCLUDE;%GTK_LIB%\GLIB-2.0\INCLUDE;%GTK_INCL%\LIBXML2;%GTK_INCL%\GDK-PIXBUF-2.0
    LIB = C:\GTK\LIB
    PATH = C:\GTK\bin (add this line)
    ---
  4. build x64 RGtk2. Two ways can do this. Both require the system admin to do it. Download RGtk2 source tarball from R archived repos. (RGtk2 v2.20.36.2) and place it under the R working folder.
    1. Open R console as the system admin. and run the following codes:install.packages("RGtk2_2.20.36.2.tar.gz",repos=NULL,INSTALL_opts="--no-html --no-help --no-multiarch",type="source"). The install option of "--no-test-load" is omitted since the runtime has been installed. After the installation, run library(RGtk2). You can find that RGtk2 will not ask if install GTK+.
    2. Open a command line (the terminal) as the system admin and go to R working folder, and type the command: R CMD INSTALL --no-help --no-html --no-multiarch --build RGtk2_2.20.36.2.tar.gz. A zip file RGtk2_2.20.36.2.zip is generated. This required the folder ~/R/x.x.x/bin in the PATH (x.x.x means the version # of R). The reason to use "--no-html" & "--no-help" is to speed the building processes. Also, the original developers did use "--no-html" too. It is easy to find out. Just open the developers' built RGtk2_2.20.36.2.zip. The folder of 'html' under RGtk2 was empty. With "--no-help", it reduced the total file size of RGtk2_2.20.36.2.zip from 15 MB to 4 MB. What a great help. :-D The option of "--no-multiarch" is definitely required; otherwise, the building processes crashed when trying to build x386 RGtk2 (not until building x64 RGtk2).

In conclusion, I think that it may not be practical to ask users to set up the GTK development pack to install RGtk2 package from its source by themselves. Thus, I decided to bundle RGtk2 & the GTK+ runtime. Also, I added more GTK+/GTK2 themes into the bundle. I will explain how to install/choose GTK+/GTK2 themes on Ubuntu/macOS/Windows 10 & 11 later. That's it.

GTK: GIMP Tool Kit; GTK+ a.k.a GTK2; GTK has been evolved to GTK3/GTK4 on unix-like OS, such as Linux.

All the best,
-- Yung-jin Lee
bear v2.9.1:- created by Hsin-ya Lee & Yung-jin Lee
Kaohsiung, Taiwan https://www.pkpd168.com/bear
Download link (updated) -> here

Complete thread:

UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,636 registered users;
93 visitors (0 registered, 93 guests [including 9 identified bots]).
Forum time: 20:23 CET (Europe/Vienna)

Nothing shows a lack of mathematical education more
than an overly precise calculation.    Carl Friedrich Gauß

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5