I can’t figure out how to give my R package’s shared library’s debug symbols source line information. What am I missing?
I create the following src/Makevars file:
PKG_CXXFLAGS=-O0 -ggdb
PKG_LIBS=-O0 -ggdb
I compile the package using R CMD INSTALL --no-multiarch --with-keep.source:
* installing to library ‘~/.local/lib/R/3.6’
* installing *source* package ‘reticulate’ ...
** using staged installation
g++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -I"$HOME/.local/lib/R/3.6/Rcpp/include" -D_FORTIFY_SOURCE=2 -O0 -ggdb -fpic -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -c RcppExports.cpp -o RcppExports.o
** libs
g++ -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o reticulate.so RcppExports.o event_loop.o libpython.o output.o python.o readline.o -O0 -ggdb -L/usr/lib64/R/lib -lR
installing to ~/.local/lib/R/3.6/00LOCK-reticulate/00new/reticulate/libs
I debug like this:
R -d gdb --slave -e 'reticulate::py_eval("print")()'
GNU gdb (GDB) 8.3
[...]
(No debugging symbols found in /usr/lib64/R/bin/exec/R)
(gdb) break py_get_formals
Function "py_get_formals" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (py_get_formals) pending.
(gdb) run
Starting program: /usr/lib/R/bin/exec/R --slave -e reticulate::py_eval\(\"print\"\)\(\)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[...]
Thread 1 "R" hit Breakpoint 1, 0x00007fffeb6b79a0 in py_get_formals(PyObjectRef, bool) () from /home/angerer/.local/lib/R/3.6/reticulate/libs/reticulate.so
(gdb) step
Single stepping until exit from function _Z14py_get_formals11PyObjectRefb,
which has no line number information.
[...]
Why does my function not have line numbers even though I specified -ggdb in both compilation? I see that only RcppExports.cpp is mentioned in the command line, is that the problem? If so, how can I change this?
Changing the Makevars doesn’t prompt recompilation.
I needed to rm -f src/*.o src/*.so before the object files get recompiled.
This is specifically for Windows. The simplest way to do it is to set the R_MAKEVARS_USER environment to point to the Makevars.win file. That seems to work. However, debug break points have stopped working!!!!
I can’t figure out how to give my R package’s shared library’s debug symbols source line information. What am I missing?
I create the following src/Makevars file:
PKG_CXXFLAGS=-O0 -ggdb
PKG_LIBS=-O0 -ggdb
I compile the package using R CMD INSTALL --no-multiarch --with-keep.source:
* installing to library ‘~/.local/lib/R/3.6’
* installing *source* package ‘reticulate’ ...
** using staged installation
g++ -std=gnu++11 -I"/usr/include/R/" -DNDEBUG -I"$HOME/.local/lib/R/3.6/Rcpp/include" -D_FORTIFY_SOURCE=2 -O0 -ggdb -fpic -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -c RcppExports.cpp -o RcppExports.o
** libs
g++ -std=gnu++11 -shared -L/usr/lib64/R/lib -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o reticulate.so RcppExports.o event_loop.o libpython.o output.o python.o readline.o -O0 -ggdb -L/usr/lib64/R/lib -lR
installing to ~/.local/lib/R/3.6/00LOCK-reticulate/00new/reticulate/libs
I debug like this:
R -d gdb --slave -e 'reticulate::py_eval("print")()'
GNU gdb (GDB) 8.3
[...]
(No debugging symbols found in /usr/lib64/R/bin/exec/R)
(gdb) break py_get_formals
Function "py_get_formals" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (py_get_formals) pending.
(gdb) run
Starting program: /usr/lib/R/bin/exec/R --slave -e reticulate::py_eval\(\"print\"\)\(\)
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[...]
Thread 1 "R" hit Breakpoint 1, 0x00007fffeb6b79a0 in py_get_formals(PyObjectRef, bool) () from /home/angerer/.local/lib/R/3.6/reticulate/libs/reticulate.so
(gdb) step
Single stepping until exit from function _Z14py_get_formals11PyObjectRefb,
which has no line number information.
[...]
Why does my function not have line numbers even though I specified -ggdb in both compilation? I see that only RcppExports.cpp is mentioned in the command line, is that the problem? If so, how can I change this?
Changing the Makevars doesn’t prompt recompilation.
I needed to rm -f src/*.o src/*.so before the object files get recompiled.
This is specifically for Windows. The simplest way to do it is to set the R_MAKEVARS_USER environment to point to the Makevars.win file. That seems to work. However, debug break points have stopped working!!!!
I am trying to set up Travis-CI to build this R package. The package builds locally with the following steps that closely mirror the build process on Travis (failed build here):
git clone --depth=50 --branch=master https://github.com/weinstockj/htslibr.git weinstockj/htslibr
cd weinstockj/htslibr/
git submodule update --init --recursive
cd htslibr/
R -e 'install.packages("Rcpp")'
R CMD build .
Travis fails with an error that suggests it cannot find a header file that is in a sub-directory of htslibr/src. Why does R CMD build fail to find the header on Travis (again, no issue locally)?
Travis set up is here , and locally I am also using Ubuntu 16.04.
Here an extract from the failed build log:
mkdir -p /tmp/Rtmpy1bhv4/Rinst23036acf1e4/htslibr/inst/include
cp htslib/htslib/*.h /tmp/Rtmpy1bhv4/Rinst23036acf1e4/htslibr/inst/include
g++ -std=gnu++11 -I"/home/travis/R-bin/lib/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I/home/travis/R-bin/include -fpic -g -O2 -c RcppExports.cpp -o RcppExports.o
g++ -std=gnu++11 -I"/home/travis/R-bin/lib/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -I/home/travis/R-bin/include -fpic -g -O2 -c util.cpp -o util.o
util.cpp:2:24: fatal error: htslib/hts.h: No such file or directory
We see that while the headers are copied to /tmp/Rtmpy1bhv4/Rinst23036acf1e4/htslibr/inst/include, this directory is not on the include path. You can fix this by adding
PKG_CPPFLAGS = -I../inst/include -DSTRICT_R_HEADERS
to Makevars (STRICT_R_HEADERS is not needed but "best practice") and using #include <hts.h> in util.cpp. However, I am not convinced that it is correct to copy the header files to inst/include in the first place. After all, these header files do not represent an API that your packge is providing to other packages. Instead, it is the API of a library that you package uses internally. I would therefore suggest to not copy the header files and use
PKG_CPPFLAGS = -Ihtslib -DSTRICT_R_HEADERS
in Makevars.
BTW, Writing R Extensions advocates a different usage pattern for the targets:
all: $(SHLIB)
$(SHLIB): <any other needed targets>
Though this point is irrelevant if you follow my suggestion to not copy the headers.
I am trying to install an R package from source, but getting an error:
* installing *source* package ‘mclust’ ...
** package ‘mclust’ successfully unpacked and MD5 sums checked
** libs
gfortran-4.8 -fPIC -g -O2 -c mclust.f -o mclust.o
gfortran-4.8 -fPIC -g -O2 -c mclustaddson.f -o mclustaddson.o
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o mclust.so mclust.o mclustaddson.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lquadmath
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mclust.so] Error 1
ERROR: compilation failed for package ‘mclust’
* removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/mclust’
Warning in install.packages :
installation of package ‘mclust’ had non-zero exit status
I don't have /usr/local/lib/gcc/x86_64-apple-darwin13.0.0, so it makes sense that it can't be found. I have /usr/local/lib/gcc/i686-apple-darwin11 and /usr/local/lib/gcc/4.8 (symlink to Homebrew installation). Where is it getting x86_64-apple-darwin13.0.0 from?
There are a lot of references to a similar error online. However, all of them are related to compiling in Xcode and resolved by updating project settings, which is not applicable here.
You need to modify the ~/.R/Makevars file. For a greater overview of this see: https://cran.r-project.org/doc/manuals/r-release/R-admin.html#OS-X-packages
Alternatively, this has been answered before in a bit more depth by #kevin-ushey in Rcpp warning: "directory not found for option '-L/usr/local/Cellar/gfortran/4.8.2/gfortran'".
What is happening is your code is not being run under gcc instead it is being forwarded to clang
You will need to change your compile statements in ~/.R/Makevars/ to gcc using:
VER=-5.3.0
CC=gcc$(VER)
CXX=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/5.3.0/lib/gcc/5
This assumes you have already installed gcc via homebrew under:
brew install gcc
(gfortran ships with gcc in brew now)
Incorporating previous solutions with additional help from the comments, the following solution has worked for me on Mac OS X High Sierra.
Create/edit ~/.R/Makevars with the following contents:
VER=-8
CC=gcc$(VER)
CXX=g++$(VER)
CXX11=g++$(VER)
CXX14=g++$(VER)
CXX17=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/8.2.0/lib/gcc/8
Note, I am using homebrew and have gcc version 8.2.0 installed.
From http://thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error/ you can fix this by downloading the optional gfortran libraries from http://r.research.att.com/libs/ and extracting them. To do this on the command line
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
I had this issue for a long time, working on a Mac. Following the other answers on this page and other questions, I did the following and it finally worked!
Step 1 - brew install gcc (it installed gcc-11 for me. If this is different for you in the future, replace gcc-11 below with the corresponding version. You can find the version by checking in the folder /usr/local/bin and seeing the latest gcc version file there)
Step 2 - xcode-select --install (this installs Xcode CLI)
Step 3 - ln -sf /usr/local/bin/gcc-11 /usr/local/bin/gcc (this makes a new gcc symlink under /usr/local/bin/. Source)
Step 4 - I did not have a ~/.R/Makevars file. Heck, I didn't even have the ~./R folder. Made the folder and the file. Here is what I wrote in the Makevars file (remember to change the GCC version in the first and last line according to the version you have. Also remember to not have the entire version number that's in the last line, in the first line. Just the overall version number - 11 in my case) -
VER=-11
CC=gcc$(VER)
CXX=g++$(VER)
CXX11=g++$(VER)
CXX14=g++$(VER)
CXX17=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11
Now restart, and voila! It works.
I'm working on MacOS Mojave (10.14.5) and on R 4.0.0. The problem here is that "CRAN R 4.0.0 builds and higher no longer use any custom compilers" (see here), so the Makevars solution does not appear to work anymore.
The solution for me was to download and install the GNU Fortran compiler from the official R-Project website. Note that you will also need Xcode and Xcode command-line tools.
After running the installer with default settings, compilation of gfortran code worked without problems.
I received the same error on MAC. All I needed to do was to install gfortran-6.1.pkg from https://cran.r-project.org/bin/macosx/tools/. Make sure that the package is installed under /usr/local/gfortran so it can be found by R.
Alternatively you can install it via homebrew typing brew cask install gfortran in the terminal (it may ask for your password).
In my case I combined this answer with this one, to produce the following code in the ~./R/.Makevars-file.
touch ~./R/.Makevars
(because it didn't exist there)
open -a BBEdit ~./R/.Makevars
(I use BBEdit as text editor)
Added the following lines to the Makevars-file:
VER=-11
CC=gcc$(VER)
CXX=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
# FLIBS=-L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11
# FLIBS = -L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`
FLIBS=`gfortran -print-search-dirs | grep ^libraries: | sed 's|libraries: =||' | sed 's|:| -L|g' | sed 's|^|-L|'`
These two lines were suggested by #KevinUshy.
# FLIBS=-L/usr/local/Cellar/gcc/11.1.0_1/lib/gcc/11
# FLIBS = -L`gfortran -print-file-name=libgfortran.dylib | xargs dirname`
I commented these out, as I figure that the final line would probably work best.
Two notes.
I have brew installed and I used brew to install gcc using the command brew install gcc.
I figure out the version-naming using brew info gcc, which gave me 11.1.0_1, but it is linked as gcc-11, so VER=-11 in the .Makevars-file.
Hope this helps others.
I am having Mac OS Catalina and in my case installation of Homebrew, the newest gcc and Gfortran 8.2.0 solved the issue.
The solution was to re-install problematic packages with Homebrew.
$ brew uninstall --ignore-dependencies --force openssl
$ brew install openssl
$ brew uninstall --ignore-dependencies --force readline
$ brew install readline
Digging this topic, if you tried these and much others approaches related to this error and got no success, I strongly recommend you to check if your OSx - just in case - deleted the .zshrc file.
If that's the case, you should create again this file in the root dir. type in your terminal:
touch .zshrc
followed by
openssl_prefix=$(brew --prefix openssl) printf "CFLAGS=-I$openssl_prefix/include \nLDFLAGS=-L$openssl_prefix/lib"
example of output:
CFLAGS=-I/usr/local/opt/openssl#3/include LDFLAGS=-L/usr/local/opt/openssl#3/lib
add them to the zshrcfile content, run
source .zshrc
to refresh the file and that`s all!
Had this problem using R on macos 12.4. It was caused by old and stale entries in my ~/.R/Makevars file. Once I commented everything out everything compiled just fine. I have XCode and brew install gcc active.
For later versions of R (R 4.0 and higher) and later operating systems, the recommended fix for this problem seems to be to install gfortran via rtools (see here, already mentioned in the answer of #lks_swrx).
When following these instructions, I ran into an additional problem, since my computer uses Apple Silicon chips (not Intel anymore), for which I wanted to add a solution here:
Download the appropriate gfortran tarball from rtools
Run tar fxz gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz -C /
Add it to your path by adding this line to your .zshrc file:
nano .zshrc (or whatever you use as text editor)
export PATH=$PATH:/opt/R/arm64/gfortran/bin
So far, so good; but the installation of DESeq2, which brought me here, did still not work, because R could not find the library. This is the fix:
Create a symlink to the gfortran library in /usr/local, so that R can find it:
ln -s /opt/R/arm64/gfortran /usr/local/gfortran (might require sudo)
I am writing an R package that has Fortran source code. In short, my problem is when I try to install the package I get the error "gfortran -m32: not found" however, I am able compile my code using gfortran -m32 when I'm not installing the package.
Detailed Version:
I have installed the newest version of R(3.1.1) along with the newest version of Rtools(31) and renamed my path variables accordingly (C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin;C:\Program Files\R\R-3.1.1\bin\x64;C:\msys;C:\Program Files (x86)\SSH Secure Shell;C:\Program Files\MiKTeX 2.9\miktex\bin).
For testing purposes, I downloaded the PropClust package from CRAN which has Fortran source code.
When I type "R CMD INSTALL PropClust_1.4.tar.gz" after building it, I get the following error:
* installing *source* package 'PropClust' ...
** libs
*** arch - i386
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:202: warning: overriding recipe for target `.m.o'
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:195: warning: ignoring old recipe for target `.m.o'
gfortran -m32 -O3 -mtune=core2 -c PropClustParallelTrials.f90 -o PropClustParallelTrials.o
gcc -m32 -I"C:/PROGRA~1/R/R-31~1.1/include" -DNDEBUG -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 -mtune=core2 -c minWhichMin.c -o minWhichMin.o
gfortran -m32 -shared -s -static-libgcc -o PropClust.dll tmp.def PropClustParallelTrials.o minWhichMin.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-31~1.1/bin/i386 -lR
gfortran -m32: not found
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:202: warning: overriding recipe for target `.m.o'
C:/PROGRA~1/R/R-31~1.1/etc/i386/Makeconf:195: warning: ignoring old recipe for target `.m.o'
cygwin warning:
MS-DOS style path detected: C:/PROGRA~1/R/R-31~1.1/bin/i386/Rterm.exe
Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-31~1.1/bin/i386/Rterm.exe
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
no DLL was created
ERROR: compilation failed for package 'PropClust'
* removing 'C:/Users/kamicz/Documents/IsotopeR/PropClust.Rcheck/PropClust'
Although it says "gfortran -m32: not found" I have compiled my code in the same window with the same options(gfortran -m32 -O3 -mtne=core2 -c a.f90 -o a.out) with no problems. Has anyone had this problem before? I am running Windows 7 64-bit if that matters.
I had a similar problem : R was invoking gfortran-4.8 - an unrecognized command on my system - instead of gfortran. This problem was fixed upon creating the file ~/.R/Makevars within my home directory. Here are the contents of Makevars which points to the appropriate gfortran installation:
F77 = gfortran
FC = gfortran
FLIBS = -L/usr/local/gfortran/lib