I'm looking for a clang plugin can remove recursive function. Does it exist? Is there a clang plugin source like apt?
Related
I've inherited some F77 code from the 1980s that I'd like to eventually use in an R package that is on CRAN. Basically I'll be substituting a slow function written in straight R with a .Call to a F77 subroutine that runs 100x faster. I've done similar heavy lifting with C in the past. However, when I compile the fortran subroutine via R CMD SHLIB I get a warning about one of the arrays being "larger than limit set by '-fmax-stack-var-size='". I can fix this by compiling explicitly with gfortran and setting -fmax-stack-var-size appropriately. However, how can I set the flag when running R CMD SHLIB? In a Makevars file? Eventually, I'll include this in a new release and submit to CRAN and I want to head off any issues. Many thanks.
Yes, in ~/.R/Makevars for your compilations, in src/Makevars for all builds of the package. CRAN has views on which options are portable so you may not be able to ship with the option in src/Makevars.
Here is what I have:
edd#rob:~$ grep ^F .R/Makevars
FLAGS=-Wall -O3 -g -pipe $(PEDANTIC) $(XTRAFLAGS)
FFLAGS=-O3 -g0 -Wall -pipe
FCFLAGS=-O3 -g0 -Wall -pipe
FC=$(CCACHE) gfortran
F77=$(CCACHE) gfortran
F95=$(CCACHE) gfortran
edd#rob:~$
where some of the other values are previoysly set as you can surmise. Note that there are several Fortran compiler variables, details as usual in Writing R Extensions.
I have been having some difficulties with my R install. I realised that I was unable to install packages and thought that it was due to having been tinkering with the packages I had installed recently. As I am a novice I thought that a clean install might fix it so I uninstalled R and Rstudio (via homebrew).
On reinstall I'm faced with the same issue. This is part of the console output from
install.packages("tidyverse")
/usr/local/opt/llvm/bin/clang -fopenmp -I"/usr/local/Cellar/r/3.5.1/lib/R/include" -DNDEBUG -I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include -fPIC -g -O3 -Wall -pedantic -std=gnu99 -mtune=native -pipe -c assumptions.c -o assumptions.o
In file included from assumptions.c:21:
/usr/local/Cellar/r/3.5.1/lib/R/include/Rinternals.h:39:11: fatal error: 'stdio.h' file not found
# include <stdio.h>
^~~~~~~~~
1 error generated.
Searching this site and others suggested that this is to do with lacking the Xcode command line tools. I have checked that these are installed.
Searching for stdio.h in terminal shows numerous versions in the various subfolders (tvos, iOS etc.)
other missing files include: stdlib.h, assert.h and unistd.h
I can provide the full output if that would help
Further searches have identified that in Xcode 10 (as is bundled with macOS Mojave), the location of the standard path for stdio.h and other utilities has moved.
"Legacy software" that looks for the macOS headers in the base system under /usr/include will not find the required files.
To patch this, Xcode includes a package to create links for such software to find the files.
For Xcode 10 the package file is located at:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
This information was sourced from the apple Developer forums
After installing this package and restarting the computer I have successfully installed the tidyverse.
I did run into another issue where my C compiler was not able to create executables but this was solved in this thread.
RcppArmadillo 0.8.400.0.0 works just fine on my computer, both from sourceCpp and cxxfunction. Now I want to upgrade to 0.8.500.0, which requires compilation from source. Then I got the error
ccache /usr/local/clang6/bin/clang++ -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/3.5/Resources/library/Rcpp/include" -I/usr/local/include -I/Applications/CPLEX_Studio128/cplex/include -I/Applications/CPLEX_Studio128/concert/include -DIL_STD -fPIC -Wall -g -O2 -c RcppArmadillo.cpp -o RcppArmadillo.o
RcppArmadillo.cpp:22:10: fatal error: 'RcppArmadillo.h' file not found
#include <RcppArmadillo.h>
^~~~~~~~~~~~~~~~~
1 error generated.
I got this error whether I ran install.packages("RcppArmadillo") in RStudio or in R console outside RStudio. My compiler is clang4, and I have no problem installing RcppParallel or compiling my own Rcpp code that uses RcppArmadillo and RcppParallel. R version: 3.5.0, MacOS High Sierra.
Edit: I looked at https://github.com/RcppCore/RcppArmadillo/issues/143, which is very relevant. I did install clang6 and gfortran 6.1, both downloaded from the CRAN website. I also changed the .R/Makevars file to reflect the changes to clang6. I have also installed ccache as suggested, to make compilation faster. Here's my Makevars:
F77 = /usr/local/gfortran/bin/gfortran
FC = $F77
FLIBS=-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin16/6.3.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
CC=ccache /usr/local/clang6/bin/clang
SHLIB_CXXLD=ccache /usr/local/clang6/bin/clang++
CXX= ccache /usr/local/clang6/bin/clang++ -Wall
CXX1X= ccache /usr/local/clang6/bin/clang++
CXX98= ccache /usr/local/clang6/bin/clang++
CXX11= ccache /usr/local/clang6/bin/clang++
CXX14= ccache /usr/local/clang6/bin/clang++
CXX17= ccache /usr/local/clang6/bin/clang++
LDFLAGS=-L/usr/local/clang6/lib
From the outputs in the R console when I was installing the package (added to the error message above), I can tell that clang6 was used for compilation. I also found the downloaded RcppArmadillo tarball, unpacked it, and ran ./configure from the command line. Nothing seemed wrong there; no config.log file was generated. This doesn't seem to be a configuration problem. Then I still got the exact same error when trying to install the package in R, after configuration, in libs. I also didn't get any message about -fopenmp. It seems that my problem is a bit different from that in the GitHub ticket.
R 3.5.x requires clang6 and adding clang6 to your system PATH variable.
Steps:
x Download and install the clang-6.0.0.pkg official package from CRAN.
x Delete your ~/.R/Makevars as it is likely set to use clang4. To do this, open Terminal and type:
sudo rm ~/.R/Makevars
x Then add to your ~/.bash_profile the following:
if [ -d "/usr/local/clang6/bin" ] ; then
export PATH="/usr/local/clang6/bin:$PATH"
fi
Note: If you are using a shell other than bash you will need to add the above into the appropriate file, e.g. for zsh add to ~/.zshrc, as this was not implemented in the official installer.
I should have a few cycles to finish writing a new unofficial Rtools installer a bit later. See: https://github.com/coatless/r-macos-rtools/issues/7
Note: Alternatively, you can remove the paths individual with
sudo vi ~/.R/Makevars
Pressing I to enter insert mode, deleting lines with clang4 in the path, and then pressing ESC + :wq to write changes to file.
Never mind, this problem went away with version 0.8.600. Later, this problem appeared again when I upgraded to RcppArmadillo 0.9.100.5.0. Somehow I only got this error when building from source; I downloaded the binary manually from the CRAN website, and used R CMD INSTALL to install the prebuilt version, and it worked; somehow R doesn't seem to know that there is a binary available for the newest version.
I did install clang6 and modified .R/Makevars to use clang6, but the same problem persisted; probably something else caused the problem.
I'm building a package containing an old f77 code that should absolutely be build with the o0 optimization option.
In the /src/Makevars of my package I added this line:
FFLAGS=-O0 -pipe -g $(LTO)
but when I compile my package, I see R is still using
the default compiling options from the /usr/lib/R/etc/Makeconf file:
gfortran -fpic -O3 -pipe -g -c Babar.f -o Babar.o
How can I override the default compilation options for the FORTRAN files of my package in R?
(I intend to distribute that package through CRAN so the compilation option should be set from the Makevars file)
There are two to three things here:
As you note, R itself uses the options encoded from its run of configure, ie built-time. See the file $RHOME/etc/Makeconf
You can override things via src/Makevars on a per-package basis. That is what you probably want here. See R's Makeconf for the list of variables, and set eg FFLAGS.
You can override things for all your builds via a per-user ~/.R/Makevars. Eg I set optimization and warning level for my builds in that file.
See the "Writing R Extensions" manual for details.
Edit: And there is 1.a) You can edit a local file $RHOME/etc/Makeconf.site too. On Debian/Ubuntu, I softlink the directory $RHOME/etc/ into /etc/R which makes that easier too.
Ok, the best solution I found for this is to do it as is done in the quadprog package (ver 1.5-5). Here is what the relevant parts of the src/Makevars file look like:
mypackage_FFLAGS = $(FPICFLAGS) $(SHLIB_FFLAGS)
all: $(SHLIB)
Babar.o: Babar.f
$(F77) $(mypackage_FFLAGS) -O1 -pipe -g -c -o Babar.o Babar.f
So, for example when you send the package to the win-builder here is what the compiler output looks like (confirming that this solution does indeed work):
gfortran -O1 -pipe -g -c -o Babar.o Babar.f
How to create a .so and .a file in UNIX. Do we have any standard utility for it?
*.a - archive library
to create it compile your sources:
gcc -c -o foo.o foo.c
gcc -c -o boo.o boo.c
ar -rsc yourlib.a foo.o boo.o
so - position independent code shared library
gcc -fPIC -shared -soname,libfoo.so.1 -o libfoo.so.1.0 foo.c boo.c
#create shared library
gcc -Os -fPIC -c test.c
gcc -shared test.so test.o
#create static library
gcc -Os -c test.c
ar rcs test.a test.o
The .a is also called a static library, and the .so is also called a dynamically loaded library.
I like the Program Library HOWTO.
This HOWTO for programmers discusses
how to create and use program
libraries on Linux. This includes
static libraries, shared libraries,
and dynamically loaded libraries.
The Yo Linux tutorial is also useful.
This tutorial discusses the philosophy
behind libraries and the creation and
use of C/C++ library "shared
components" and "plug-ins". The
various technologies and methodologies
used and insight to their appropriate
application, is also discussed. In
this tutorial, all libraries are
created using the GNU Linux compiler.
Take a look at this Makefile I wrote when I was new to C. It clearly shows how to generate and correctly link .a and .so files from a simple demo source.