Search code examples
c++rmacosllvm-clang

How to compile a whole R source packages with Clang -Wno-nullability-completeness option in OSX 10.15


Based on several postings in stackoverflow, in OSX 10.15, I can suppress warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness] from conftest.c by clang -Wno-nullability-completeness -o conftest -g -O2 -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include conftest.c or gcc -Wno-nullability-completeness conftest.c. But how can I implement this for compiling a whole R pacakge from the source ? I added -Wno-nullability-completeness in R Makevers like this :

CC=clang -Wno-nullability-completeness
CXX=clang++ -Wno-nullability-completeness
CFLAGS=-Wno-nullability-completeness -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe
CXXFLAGS=-Wno-nullability-completeness -g -O3 -Wall -pedantic -std=c++11 -mtune=native
LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include

but it did not work. Any suggestions or pointers will be seriously appreciated.

My system;

sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.2
BuildVersion:   19C57

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.2.0_2/libexec/gcc/x86_64-apple-darwin19/9.2.0/lto-wrapper
Target: x86_64-apple-darwin19
Configured with: ../configure --build=x86_64-apple-darwin19 --prefix=/usr/local/Cellar/gcc/9.2.0_2 --libdir=/usr/local/Cellar/gcc/9.2.0_2/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.2.0_2' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk
Thread model: posix
gcc version 9.2.0 (Homebrew GCC 9.2.0_2)

clang -v
clang version 9.0.0 (tags/RELEASE_900/final)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

brew info R
R: stable 3.6.2 (bottled)
Software environment for statistical computing
https://www.r-project.org/
/usr/local/Cellar/R/3.6.2 (2,123 files, 58.5MB)
  Poured from bottle on 2019-12-14 at 09:37:12
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/r.rb
==> Dependencies
Build: pkg-config ✔
Required: gcc ✔, gettext ✔, jpeg ✔, libpng ✔, openblas ✔, pcre ✔, readline ✔, xz ✔

Flags:

CPATH=/usr/local/include
LDFLAGS=-L/usr/local/opt/llvm/lib
CPPFLAGS=-I/usr/local/opt/llvm/include
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk

Edit 1

From a suggestion by Ralf Stubner, I looked at an installer output generated by install.package("e1071", keep_outputs=T) ;

All my packages loaded Tue Dec 31 16:23:24 2019* installing *source* package ‘e1071’ ...
** package ‘e1071’ successfully unpacked and MD5 sums checked
** using staged installation
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether clang++ -std=gnu++11 accepts -g... yes
** libs
clang -I"/usr/local/Cellar/r/3.6.2/lib/R/include" -DNDEBUG   -I/usr/local/opt/gettext/include -I/usr/local/opt/readline/include -I/usr/local/include  **-fPIC  -g -O2**  -c Rsvm.c -o Rsvm.o
In file included from Rsvm.c:2:
/usr/local/include/stdio.h:67:13: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
extern FILE *__stdinp ........;

and I realized that CXXFLAGs in my Makevars may not be read by clang at all. A following is my current Makevars;

LLVM_LOC = /usr/local/opt/llvm
CC=clang
CXX=clang++
CXX11=clang++

CFLAGS = -g -O3 -Wall -pipe -pedantic -Wno-nonnull -std=gnu99 -mtune=native
CXXFLAGS = -g -O3 -Wall -pipe -Wno-nonnull -pedantic -std=c++11 -mtune=native
CXX11FLAGS = -g -O3 -Wall -pipe -Wno-nonnull -pedantic -std=c++11 -mtune=native

LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include

Solution

  • Ok I figured this out. Thanks to the help from RalfStubner. I realized that I was not putting Makevars in the right location. A default location of Makevars should be ~/.R/Makevars. Now, CXXFLAGS in the Makevars is read and -Wno-nonnull is applied. My latest Makevars is as follows;

    LLVM_LOC = /usr/local/opt/llvm
    CC=$(LLVM_LOC)/bin/clang -fopenmp
    CXX=$(LLVM_LOC)/bin/clang++ -fopenmp
    
    CC=clang
    CXX=clang++
    CXX11=clang++
    
    CFLAGS = -g -O3 -Wall -pipe -pedantic -Wno-nonnull -std=gnu99 -mtune=native -pipe
    CXXFLAGS = -g -O3 -Wall -pipe -Wno-nonnull -pedantic -std=c++11 -mtune=native
    CXX11FLAGS = -g -O3 -Wall -pipe -Wno-nonnull -pedantic -std=c++11 -mtune=native
    
    LDFLAGS=-L/usr/local/opt/gettext/lib -L$(LLVM_LOC)/lib -Wl,-rpath,$(LLVM_LOC)/lib
    CPPFLAGS=-I/usr/local/opt/gettext/include -I$(LLVM_LOC)/include