Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to compile with R 3.4.0 (homebrew) under Mac OS #191

Closed
gtms opened this issue May 11, 2017 · 36 comments
Closed

Fail to compile with R 3.4.0 (homebrew) under Mac OS #191

gtms opened this issue May 11, 2017 · 36 comments

Comments

@gtms
Copy link

gtms commented May 11, 2017

From the console:

installing to /usr/local/lib/R/3.4/site-library/igraph/libs
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded

Error: package or namespace load failed for ‘igraph’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so':
  dlopen(/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so, 6): Symbol not found: __ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5rfindEcm
  Referenced from: /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
  Expected in: flat namespace
 in /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/3.4/site-library/igraph’

The downloaded source packages are in
	‘/private/var/folders/p_/mry8zmqd2dl5wk98nzlys3hh01gkrs/T/Rtmp2dBNry/downloaded_packages’
Warning message:
In install.packages(pkg, repos = "http://cran.r-project.org") :
  installation of package ‘igraph’ had non-zero exit status

Also fails to install development version:

devtools::install_github("igraph/rigraph")
Downloading GitHub repo igraph/rigraph@master
from URL https://api.github.com/repos/igraph/rigraph/zipball/master
Installing igraph
'/usr/local/Cellar/r/3.4.0_1/R.framework/Resources/bin/R' --no-site-file  \
  --no-environ --no-save --no-restore --quiet CMD INSTALL  \
  '/private/var/folders/p_/mry8zmqd2dl5wk98nzlys3hh01gkrs/T/Rtmp2dBNry/devtools41cf4e0714dc/igraph-rigraph-057cc9d'  \
  --library='/usr/local/lib/R/3.4/site-library' --install-tests 

* installing *source* package ‘igraph’ ...
checking for gcc... /usr/local/Cellar/gcc/7.1.0/bin/gcc-7
checking whether the C compiler works... yes
installing to /usr/local/lib/R/3.4/site-library/igraph/libs
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘igraph’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so':
  dlopen(/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so, 6): Symbol not found: __ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5rfindEcm
  Referenced from: /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
  Expected in: flat namespace
 in /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/3.4/site-library/igraph’
Installation failed: Command failed (1)

Any hints?

@gaborcsardi
Copy link
Contributor

Looks like you are not linking to the standard C++ library, so maybe your R installation is broken? CAn you install other packages with C++ code?

@gtms
Copy link
Author

gtms commented May 12, 2017

For the record, this is not caused by a faulty R installation. igraphs is currently the only R package failing to link with gcc7 on this machine (Bioconductor successfully installed). On another machine of mine, running Fedora Linux, installation is successful.

As this forum shows other unattended reports of failing igraphs installations in the same circumstances, I think that closing this thread without further discussion is premature.

@gaborcsardi gaborcsardi reopened this May 12, 2017
@ck37
Copy link

ck37 commented May 27, 2017

I also ran into this issue installing from CRAN using homebrew R 3.4.0_1 on OSX with gcc-7, due to the reverse dependency from lintr. Even installing the binary package yields an error when I try to load the package. Other packages (devtools, xgboost, bartMachine, glmnet, dplyr, randomForest, etc.) install from source just fine.

install.packages("igraph")
installing to /usr/local/lib/R/3.4/site-library/igraph/libs
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘igraph’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so':
  dlopen(/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so, 6): Symbol not found: __ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5rfindEcm
  Referenced from: /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
  Expected in: flat namespace
 in /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/usr/local/lib/R/3.4/site-library/igraph’
Warning in install.packages :
  installation of package ‘igraph’ had non-zero exit status

No benefit from trying the dev version:

devtools::install_github("gaborcsardi/pkgconfig")
devtools::install_github("igraph/rigraph")
installing to /usr/local/lib/R/3.4/site-library/igraph/libs
** R
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
Error: package or namespace load failed for ‘igraph’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so':
  dlopen(/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so, 6): Symbol not found: __ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5rfindEcm
  Referenced from: /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
  Expected in: flat namespace
 in /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
Error: loading failed
Execution halted
ERROR: loading failed

@gtms
Copy link
Author

gtms commented May 29, 2017

This remains very puzzling.

I have now followed the instructions found here, i.e, removed .libPath() directories and reinstalled R. All R packages (including bioconductor) were thus successfully compiled with gcc-7, yet igraph still fails to compile with the same error.

@gaborcsardi, would it be possible that some system libraries, outside of the R installation tree, need to be recompiled in order to satisfy igraph specific dependencies?

@gtms
Copy link
Author

gtms commented May 29, 2017

In addition, the binary version of the package does not install as well:

R> library(igraph)
Error: package or namespace load failed for ‘igraph’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so':
  dlopen(/usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so, 6): Library not loaded: /Library/Frameworks/R.framework/Versions/3.3/Resources/lib/libgfortran.3.dylib
  Referenced from: /usr/local/lib/R/3.4/site-library/igraph/libs/igraph.so
  Reason: image not found

@ck37, did I read correctly that the binary version installs properly on your system?

@ck37
Copy link

ck37 commented May 29, 2017

@gtms you're right, I can install it without error but I do get that error message when I load the package :/

@ck37
Copy link

ck37 commented Jun 4, 2017

Update: the solution is just to modify ~/.R/Makevars to temporarily use clang for this package, then it will compile fine. I had to do the same thing for magick (ropensci/magick#54).

@gtms
Copy link
Author

gtms commented Jun 5, 2017

Thanks @ck37, success.

For future reference, I'm posting my ~/.R/Makevars:

LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include

# CC=/usr/local/Cellar/gcc/7.1.0/bin/gcc-7
CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
# CXX=/usr/local/Cellar/gcc/7.1.0/bin/g++-7
CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
# CXX1X=/usr/local/bin/g++-7
CXX1X=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
SHLIB_CXXLD=/usr/local/Cellar/gcc/7.1.0/bin/g++-7
FC=/usr/local/Cellar/gcc/7.1.0/bin/gfortran-7
F77=/usr/local/Cellar/gcc/7.1.0/bin/gfortran-7
MAKE=make -j8

SHLIB_OPENMP_CFLAGS=-fopenmp
SHLIB_OPENMP_CXXFLAGS=-fopenmp
SHLIB_OPENMP_FCFLAGS=-fopenmp
SHLIB_OPENMP_FFLAGS=-fopenmp

@gaborcsardi, closed.

@gtms gtms closed this as completed Jun 5, 2017
@ck37
Copy link

ck37 commented Jun 5, 2017 via email

@gtms gtms reopened this Jun 5, 2017
@omarparr
Copy link

omarparr commented Jun 7, 2017

How do I actually open and modify the Makevars file?

@ck37
Copy link

ck37 commented Jun 7, 2017 via email

@djhurio
Copy link

djhurio commented Jul 21, 2017

The compilation of igraph 1.1.1 fails also on Windows 8 with the latest R (3.4.1) and Rtools (3.4.0.1964).

@achekroud
Copy link

achekroud commented Oct 31, 2017

did y'all install using homebrew? I am also running into this same issue installing the qgraph package.

somehow doing the following managed to fix it (stolen from homebrew-php)

wget -c http://www.ijg.org/files/jpegsrc.v8d.tar.gz
tar xzf jpegsrc.v8d.tar.gz
cd jpeg-8d
./configure
make
cp ./.libs/libjpeg.8.dylib /usr/local/opt/jpeg/lib

then retrying install.packages("qgraph")

c.f. stack overflow and homebrew-php github

@souzapd
Copy link

souzapd commented Nov 4, 2017

I have noticed that R.framework is missing on /Library/Frameworks when installed through homebrew (I was using R 3.4.2, Homebrew Homebrew 1.3.6-169-g2af9813).

I uninstalled everything and installed R from CRAN (the .pkg installer. I attempted to install it through brew, but I got an error), as well as XQuartz. Then igraph installed without a hitch.

@gustavahlberg
Copy link

I have the same issue. Any updates or resolve?

@admercs
Copy link

admercs commented Jul 6, 2018

None of the solutions provided here worked for me.

@akahanaton
Copy link

got the same error, any helps, thanks

@ashiklom
Copy link

ashiklom commented Sep 11, 2018

Can confirm that installing igraph works if CC and CXX are temporarily set to clang/clang++, respectively. I.e. the following changes to one's ~/.R/Makevars:

CC = clang
CXX = clang++

@fonnesbeck
Copy link

This does not work on 3.6.1 either, and on my system (macOS 10.14.6), there is no ~/.R/Makevars to edit. Creating one and adding the CC, CXX flags does not help.

@zhiyzuo
Copy link

zhiyzuo commented Sep 22, 2019

My .R/Makevars based on those from @ashiklom and @gtms helped me install igraph on macOS Catalina with R 3.6.1:

LDFLAGS=-L/usr/local/opt/gettext/lib -L/usr/local/opt/llvm/lib
CPPFLAGS=-I/usr/local/opt/gettext/include -I/usr/local/opt/llvm/include

CC=clang
CCX=clang++

@jokedurnez
Copy link

Ran into similar issues, and can confirm setting CC and CCX helped !

@jankowtf
Copy link

jankowtf commented Sep 28, 2021

After running

brew install gcc

and with this content of ~/.R/Makevars

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/lib/gcc/11

I still see the fortran error:

> renv::install("igraph")
Retrieving 'https://packagemanager.rstudio.com/all/latest/src/contrib/igraph_1.2.6.tar.gz' ...
	OK [file is up to date]
Installing igraph [1.2.6] ...
	FAILED
Error installing package 'igraph':
==================================

* installing to library ‘/Volumes/GoogleDrive/My Drive/Code/baem.dev/renv/staging/1’
* installing *source* package ‘igraph’ ...
** package ‘igraph’ successfully unpacked and MD5 sums checked
** using staged installation
checking for gcc... clang -mmacosx-version-min=10.13
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether clang -mmacosx-version-min=10.13 accepts -g... yes
checking for clang -mmacosx-version-min=10.13 option to accept ISO C89... none needed
checking whether we are using the GNU Fortran compiler... no
checking whether gfortran -mmacosx-version-min=10.13 accepts -g... no
checking whether we are using the GNU C++ compiler... yes
checking whether clang++ -mmacosx-version-min=10.13 -std=gnu++11 accepts -g... yes
checking how to run the C++ preprocessor... clang++ -mmacosx-version-min=10.13 -std=gnu++11 -E
checking for rintf... yes
checking for finite... yes
checking for expm1... yes
checking for rint... yes
checking for log2... yes
checking for logbl... yes
checking for snprintf... yes
checking for log1p... yes
checking for round... yes
checking for fmin... yes
checking for stpcpy... yes
checking how to run the C preprocessor... clang -mmacosx-version-min=10.13 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking whether stpcpy is declared... yes
checking sys/times.h usability... yes
checking sys/times.h presence... yes
checking for sys/times.h... yes
checking net/if.h usability... yes
checking net/if.h presence... yes
checking for net/if.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking net/if_dl.h usability... yes
checking net/if_dl.h presence... yes
checking for net/if_dl.h... yes
checking sys/sockio.h usability... yes
checking sys/sockio.h presence... yes
checking for sys/sockio.h... yes
checking sys/un.h usability... yes
checking sys/un.h presence... yes
checking for sys/un.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/file.h usability... yes
checking sys/file.h presence... yes
checking for sys/file.h... yes
checking for struct sockaddr.sa_len... yes
checking for xml2-config... /usr/bin/xml2-config
checking for xmlSAXUserParseFile in -lxml2... yes
checking libxml/parser.h usability... yes
checking libxml/parser.h presence... yes
checking for libxml/parser.h... yes
checking for __gmpz_add in -lgmp... no
checking for glp_read_mps in -lglpk... no
configure: creating ./config.status
config.status: creating src/Makevars.tmp
config.status: creating src/Makevars
config.status: creating src/config.h
** libs
gfortran -mmacosx-version-min=10.13 -fno-optimize-sibling-calls  -fPIC  -Wall -g -O2  -c AMD/Source/amd.f -o AMD/Source/amd.o
make: gfortran: No such file or directory
make: *** [AMD/Source/amd.o] Error 1
ERROR: compilation failed for package ‘igraph’
* removing ‘/Volumes/GoogleDrive/My Drive/Code/baem.dev/renv/staging/1/igraph’
------------------------------------------------------------------------------ 
R was unable to find the gfortran binary.
gfortran is required for the compilation of FORTRAN source files.
Please check that gfortran is installed and available on the PATH.
Please see https://stackoverflow.com/q/35999874 for more information.

Reason(s):
- 'make: gfortran: No such file or directory'

I've looked into https://stackoverflow.com/questions/35999874/mac-os-x-r-error-ld-warning-directory-not-found-for-option, but updated the gcc version to 11 since this seems to be the current version listed at https://formulae.brew.sh/formula/gcc

@ntamas
Copy link
Member

ntamas commented Sep 29, 2021

gfortran is either not on your path or is a broken symlink. On my machine, Homebrew is in /usr/local, so gcc-from-Homebrew is in /usr/local/Cellar/gcc/11.2.0. The appropriate executables are symlinked as follows:

❯ ls -la /usr/local/bin/gfortran*
lrwxr-xr-x 1 tamas admin 33 Sep  1 00:13 /usr/local/bin/gfortran -> ../Cellar/gcc/11.2.0/bin/gfortran*
lrwxr-xr-x 1 tamas admin 36 Sep  1 00:13 /usr/local/bin/gfortran-11 -> ../Cellar/gcc/11.2.0/bin/gfortran-11*

Do these symlinks exist for you? Does gfortran work from the command line? (E.g., try gfortran -v).

@jankowtf
Copy link

jankowtf commented Sep 30, 2021

@ntamas thanks for your comment.

I would also much rather have homebrew in usr/local - not sure how I ended up with my current setting, tbh ;-)

The syllinks in fact do not exist and `gfortran -v´ gives me the following

jankothyson@macbook ~ % gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/11.2.0/libexec/gcc/aarch64-apple-darwin20/11.1.0/lto-wrapper
Target: aarch64-apple-darwin20
Configured with: ../configure --prefix=/opt/homebrew/Cellar/gcc/11.2.0 --libdir=/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-11 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 11.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --build=aarch64-apple-darwin20 --with-system-zlib --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Homebrew GCC 11.2.0) 

I think I'll try to start over with a fresh setup of homebrew so that things live where they belong


UPDATE

Seems that /opt/homebrew is indeed the correct location for homebrew on ARM:

This script installs Homebrew to its preferred prefix (/usr/local for macOS Intel, /opt/homebrew for Apple Silicon and /home/linuxbrew/.linuxbrew for Linux) so that you don’t need sudo when you brew install.

(taken from https://docs.brew.sh/Installation)

@ntamas
Copy link
Member

ntamas commented Sep 30, 2021

This is just a stab in the dark, but maybe the PATH that R is using when compiling packages is different from your system PATH and does not include /opt/homebrew/bin? That's one possible explanation why gfortran works from the command line but not when R is compiling packages. Check the contents of $R_HOME/etc/Makeconf and/or ~/.R/Makevars to see if these files contain path settings for the Fortran compiler.

Incidentally, @szhorvat is struggling with similar issues on macOS when he tries to compile igraph; in his case, gfortran comes from Macports and R does not seem to be able to find it. Maybe he has more ideas about how to resolve this problem, or at least he can share what dead ends he has tried so far.

@iosonofabio
Copy link
Member

FWIW, I also had R doing that to me, so it's good to check

@vtraag
Copy link
Member

vtraag commented Oct 1, 2021

You don't run macOS though, do you @iosonofabio? Are you saying you get the same problem with missing gfortran on Arch?

@jankowtf
Copy link

jankowtf commented Oct 1, 2021

@ntamas thanks again for your follow up suggestions!

In my pursuit of sorting this mess out somewhat systematically, I wiped homebrew and Xcode completely and reinstalled everything from scratch "by the book". This is where I stand currently:

The known knowns by now

  • I'm now positive that the location of homebrew and the software it installs now live under /opt/homebrew instead of /usr/local for ARM architectures
  • Hence, running ls -la /usr/local/bin/gfortran* of course won't give me anything, but ls -la /opt/homebrew/bin/gfortran* does:
    jankothyson@macbook gcc % ls -la /opt/homebrew/bin/gfortran*
    lrwxr-xr-x  1 jankothyson  admin  33 Sep 30 23:35 /opt/homebrew/bin/gfortran -> ../Cellar/gcc/11.2.0/bin/gfortran
    lrwxr-xr-x  1 jankothyson  admin  36 Sep 30 23:35 /opt/homebrew/bin/gfortran-11 -> ../Cellar/gcc/11.2.0/bin/gfortran-11```
    
  • As of yesterday, the error that I'm getting has shifted from make: gfortran-11: No such file or directory to this:
    checking for gcc... gcc-11
    checking whether the C compiler works... no
    configure: error: in '/private/var/folders/ry/bnfxqrqd1bd4mxtvgvnsr9j80000gn/T/Rtmp7veSvZ/renv-package-3157bb9d273/igraph':
    configure: error: C compiler cannot create executables```
    
    

The known unknowns

  • What exactly should my ./R/Makevars actually look like? My current state is puzzled together from various blog posts, SO posts and/or GitHub issues and looks like this:
    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/opt/homebrew/Cellar/gcc/11.2.0/lib/gcc/11
    FC=gfortran$(VER)
    CPPFLAGS += -Xclang -fopenmp
    LDFLAGS += -lomp
    
    TBH, I don't really understand any of this except that it has to do with compiler stuff for C and Fortran, so I'm way out of my depth here 😄
  • Where exaclty do I find the config.log that is referenced in the error message`
  • The latest two rows in my Makevars stem from this SO post. Trying to understand the answer is where I left off yesterday

The things I thought about trying next

  • Dig deeper into some of the suggestions that @ntamas presented
  • Playing around with symlinks for C compiler stuff (I'm guessing this will mainly have to do with gcc

UPDATE 2021-10-01 10:24

@ntamas
Copy link
Member

ntamas commented Oct 1, 2021

configure: error: C compiler cannot create executables

This is a misleading error message; it typically happens when the ./configure script within an autoconf-based package is invoked with extra CFLAGS or other compiler flags that the compiler does not understand. Since autoconf first tries to compile a basic C program with the given C compiler and it passes CFLAGS to the compiler, any erroneous flags in CFLAGS will produce this error even though there's nothing wrong with the compiler -- only with the flags passed to it.

What exactly should my ./R/Makevars actually look like?

On my machine it is nonexistent. As far as I know it is meant to contain customizations to the stock build system configuration that ships with R, and on my machine things work without any customizations.

I would first try with removing CFLAGS, CXXFLAGS and CPPFLAGS from your Makevars file to see if any of these flags are the ones that the compiler is having problems with.

Where exaclty do I find the config.log that is referenced in the error message

It's in the temporary build folder that R creates during the installation (and deletes subsequently). If you want to take a look at it, maybe the easiest way is to download the source package directly from CRAN, extracting it to a folder and then running R CMD install --build from that folder.

@ntamas
Copy link
Member

ntamas commented Oct 10, 2021

So, for everyone who tries to set up a custom C or Fortran compiler in ~/.R/Makevars and subsequently compile igraph with it from Github using devtools::install_github() - I have finally found why the build fails in such cases. It has nothing to do with igraph but with a build step in pkgtools::build() that tries to append some additional compiler flags to CFLAGS, CPPFLAGS and CXXFLAGS using withr::local_makevars(). It turns out that withr::local_makevars() has a bug that prevents it from using the settings ~/.R/Makevars if it exists. The solution is to install the development version of withr (or any version later than 2.4.2; at the time of writing, there is no such version so you need to install from Github):

devtools::install_github("r-lib/withr@master")

The commit that fixes the problem in withr is this one.

@jankowtf
Copy link

jankowtf commented Oct 12, 2021

@ntamas thanks, that sounds very promising!

However, I cannot piece everything together yet as makevars & Co. are completely new to me.

Would you mind writing down a short "recipe for dummies" on what to do exactly, step by step? 😬

I installed the dev version of withr, but now I'm lost re: when/how to call withr::local_makevars(), how to parameterize it and/or what the "right" content of my ~/.R/Makevars should look like.

This would be so much appreciated :-)

@szhorvat
Copy link
Member

szhorvat commented Oct 12, 2021

but now I'm lost re: when/how to call withr::local_makevars()

If you just want to compile igraph, you don't need to. It is sufficient to have the dev version of withr installed.

what the "right" content of my ~/.R/Makevars should look like.

My ~/.R/Makevars, used with MacPorts, looks like this:

CC = /opt/local/bin/clang-mp-12
CXX = /opt/local/bin/clang++-mp-12
FC = /opt/local/bin/gfortran-mp-11
F77 = /opt/local/bin/gfortran-mp-11
FLIBS = -L/opt/local/lib/gcc11 -lgfortran -lquadmath -lm

This is just an example. The principle is:

  • Give full paths to your preferred compilers. CC is for C, CXX is for C++, FC is for Fortran. I think F77 is no longer necessary, but I'm not sure.
  • FLIBS should contains the options necessary to link programs which include Fortran components. -L should be followed by the directory containing libgfortran.dylib. Use the one that matches your Fortran compiler. Make sure -lgfortran is present.

There is a risk of incompatibility if you don't use the same compilers that were used to compile R itself. See the compilers which are used by the official R distribution. I am not sure how high the risk is with Fortran, but to be safe, it might make sense to only specify the Fortran compiler in Makevars, and leave CC and CXX at their default values.

@jankowtf
Copy link

jankowtf commented Oct 12, 2021

@szhorvat thanks so much, that was the missing piece!

Based on your Makevars, I've tried to adapt my version to accommodate for the suggestions at https://mac.r-project.org/tools/ regarding which gfortran binary to use for ARM (I used this one in particular).

After some troubleshooting (the evolution of which can be followed by looking at the commented-out vars and me trying to understand why that particular line didn't work), this is the version that got me through a clean install both via R CMD install --build igraph (to be able to look at config.log) as suggested by @ntamas as well as via install.packages("igraph", type = "source"):

VER=-11

#CC = /opt/local/bin/clang-mp-12
#CC = /usr/bin/clang$(VER)               # based on 'which clang'
#CC = /usr/local/gfortran/bin/gcc$(VER)  # based on following instructions to use 'gfortran' from https://mac.r-project.org/tools/
CC = /usr/local/gfortran/bin/gcc         # '[...]/bin/gcc-11' didn't exist on my machine

#CXX = /opt/local/bin/clang++-mp-12
#CXX = /usr/bin/clang++$(VER)            # based on 'which clang++'
CXX = /usr/local/gfortran/bin/g++$(VER)  # based on following instructions to use 'gfortran' from https://mac.r-project.org/tools/
CXX = /usr/local/gfortran/bin/g++        # '[...]/bin/g++-11' didn't exist on my machine

#FC = /opt/local/bin/gfortran-mp-11
#FC = /usr/local/gfortran/bin/gfortran-mp$(VER) # based on following instructions to use 'gfortran' from https://mac.r-project.org/tools/
#FC = /usr/local/gfortran/bin/gfortran$(VER)    # '[...]/bin/gfortran-11' didn't exist on my machine
FC = /usr/local/gfortran/bin/gfortran    # '[...]/gfortran-11' didn't exist on my machine


#F77 = /opt/local/bin/gfortran-mp-11
F77 = /usr/local/gfortran/bin/gfortran   # '[...]/gfortran-11' didn't exist on my machine

#FLIBS = -L/opt/local/lib/gcc11 -lgfortran -lquadmath -lm
#FLIBS = -L//usr/local/gfortran/lib/gcc11 -lgfortran -lquadmath -lm # based on following instructions to use 'gfortran' from https://mac.r-project.org/tools/
FLIBS = -L//usr/local/gfortran/lib/gcc11 -lgfortran -lm # 'ld: library not found for -lquadmath'

Remaining known unknowns

Apparently I still don't understand the following things:

  • the -mp part in your paths and why I needed to drop this completely
  • the diffs in version numbers 11 vs. 12, when to use which and why I can't find any of the [...]/bin/<binary-name>-11 binaries on my machine
  • What -lquadmath does and why I would need it (I don't seem to have it on my machine)

@jankowtf
Copy link

jankowtf commented Oct 12, 2021

@ntamas looked into config.log as you suggested and that was sooo helpful!

After extracting the package source code, running R CMD install --build igraph and troubleshooting the content of my Makevars (see comment above) - dare I say - I think I got it to work!!! 🥳

Below I posted those parts of config.log that seemed relevant for potential further troubleshooting. The complete log file is also attached

Apparently there are still a couple of warnings and errors even though the build went through per se 👉 should these bother me?

Also tried install.packages("igraph", type = "source") afterwards and this also went through 🤩

[...]
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:33:6: warning: conflicting types for built-in function 'rintf'; expected 'float(float)' [-Wbuiltin-declaration-mismatch]
   33 | char rintf ();
      |      ^~~~
~
conftest.c:21:1: note: 'rintf' is declared in header '<math.h>'
   20 | # include <limits.h>
   21 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for finite
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:34:6: warning: conflicting types for built-in function 'finite'; expected 'int(double)' [-Wbuiltin-declaration-mismatch]
   34 | char finite ();
      |      ^~~~~~
Undefined symbols for architecture arm64:
  "_finite", referenced from:
      _main in ccKLLndv.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
configure:3940: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "igraph"
| #define PACKAGE_TARNAME "igraph"
| #define PACKAGE_VERSION "1.2.6"
| #define PACKAGE_STRING "igraph 1.2.6"
| #define PACKAGE_BUGREPORT "csardi.gabor@gmail.com"
| #define PACKAGE_URL ""
| #define HAVE_GFORTRAN 1
| #define HAVE_RINTF 1
| /* end confdefs.h.  */
| /* Define finite to an innocuous variant, in case <limits.h> declares finite.
|    For example, HP-UX 11i <limits.h> declares gettimeofday.  */
| #define finite innocuous_finite
| 
| /* System header to define __stub macros and hopefully few prototypes,
|     which can conflict with char finite (); below.
|     Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
|     <limits.h> exists even on freestanding compilers.  */
| 
| #ifdef __STDC__
| # include <limits.h>
| #else
| # include <assert.h>
| #endif
| 
| #undef finite
| 
| /* Override any GCC internal prototype to avoid an error.
|    Use char because int might match the return type of a GCC
|    builtin and then its argument prototype would still apply.  */
| #ifdef __cplusplus
| extern "C"
| #endif
| char finite ();
| /* The GNU C library defines this for functions which it implements
|     to always fail with ENOSYS.  Some functions are actually named
|     something starting with __ and the normal name is an alias.  */
| #if defined __stub_finite || defined __stub___finite
| choke me
| #endif
| 
| int
| main ()
| {
| return finite ();
|   ;
|   return 0;
| }
configure:3940: result: no
configure:3940: checking for expm1
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:34:6: warning: conflicting types for built-in function 'expm1'; expected 'double(double)' [-Wbuiltin-declaration-mismatch]
   34 | char expm1 ();
      |      ^~~~~
conftest.c:22:1: note: 'expm1' is declared in header '<math.h>'
   21 | # include <limits.h>
   22 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for rint
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:35:6: warning: conflicting types for built-in function 'rint'; expected 'double(double)' [-Wbuiltin-declaration-mismatch]
   35 | char rint ();
      |      ^~~~
conftest.c:23:1: note: 'rint' is declared in header '<math.h>'
   22 | # include <limits.h>
   23 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for log2
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:36:6: warning: conflicting types for built-in function 'log2'; expected 'double(double)' [-Wbuiltin-declaration-mismatch]
   36 | char log2 ();
      |      ^~~~
conftest.c:24:1: note: 'log2' is declared in header '<math.h>'
   23 | # include <limits.h>
   24 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for logbl
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:37:6: warning: conflicting types for built-in function 'logbl'; expected 'long double(long double)' [-Wbuiltin-declaration-mismatch]
   37 | char logbl ();
      |      ^~~~~
conftest.c:25:1: note: 'logbl' is declared in header '<math.h>'
   24 | # include <limits.h>
   25 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for snprintf
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:38:6: warning: conflicting types for built-in function 'snprintf'; expected 'int(char *, long unsigned int,  const char *, ...)' [-Wbuiltin-declaration-mismatch]
   38 | char snprintf ();
      |      ^~~~~~~~
conftest.c:26:1: note: 'snprintf' is declared in header '<stdio.h>'
   25 | # include <limits.h>
   26 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for log1p
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:39:6: warning: conflicting types for built-in function 'log1p'; expected 'double(double)' [-Wbuiltin-declaration-mismatch]
   39 | char log1p ();
      |      ^~~~~
conftest.c:27:1: note: 'log1p' is declared in header '<math.h>'
   26 | # include <limits.h>
   27 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for round
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:40:6: warning: conflicting types for built-in function 'round'; expected 'double(double)' [-Wbuiltin-declaration-mismatch]
   40 | char round ();
      |      ^~~~~
conftest.c:28:1: note: 'round' is declared in header '<math.h>'
   27 | # include <limits.h>
   28 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for fmin
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:41:6: warning: conflicting types for built-in function 'fmin'; expected 'double(double,  double)' [-Wbuiltin-declaration-mismatch]
   41 | char fmin ();
      |      ^~~~
conftest.c:29:1: note: 'fmin' is declared in header '<math.h>'
   28 | # include <limits.h>
   29 | #else
configure:3940: $? = 0
configure:3940: result: yes
configure:3940: checking for stpcpy
configure:3940: /usr/local/gfortran/bin/gcc -o conftest -falign-functions=64 -Wall -g -O2 -I/opt/R/arm64/include  conftest.c  -lm >&5
conftest.c:42:6: warning: conflicting types for built-in function 'stpcpy'; expected 'char *(char *, const char *)' [-Wbuiltin-declaration-mismatch]
   42 | char stpcpy ();
      |      ^~~~~~
configure:3940: $? = 0
configure:3940: result: yes
configure:3954: checking how to run the C preprocessor
configure:3985: /usr/local/gfortran/bin/gcc -E -I/opt/R/arm64/include conftest.c
configure:3985: $? = 0
configure:3999: /usr/local/gfortran/bin/gcc -E -I/opt/R/arm64/include conftest.c
conftest.c:20:10: fatal error: ac_nonexistent.h: No such file or directory
   20 | #include <ac_nonexistent.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
configure:3999: $? = 1
configure: failed program was:

[...]

| #include <ac_nonexistent.h>
configure:4024: result: /usr/local/gfortran/bin/gcc -E
configure:4044: /usr/local/gfortran/bin/gcc -E -I/opt/R/arm64/include conftest.c
configure:4044: $? = 0
configure:4058: /usr/local/gfortran/bin/gcc -E -I/opt/R/arm64/include conftest.c
conftest.c:20:10: fatal error: ac_nonexistent.h: No such file or directory
   20 | #include <ac_nonexistent.h>
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
configure:4058: $? = 1

[...]

configure:4547: checking for __gmpz_add in -lgmp
configure:4572: /usr/local/gfortran/bin/g++ -o conftest -falign-functions=64 -Wall -g -O2 -falign-functions=64 -Wall -g -O2 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include  conftest.cpp -lgmp   >&5
ld: library not found for -lgmp
collect2: error: ld returned 1 exit status
configure:4572: $? = 1
configure: failed program was:

[...] 

## ----------------- ##
## Output variables. ##
## ----------------- ##

CC='/usr/local/gfortran/bin/gcc'
CFLAGS='-falign-functions=64 -Wall -g -O2 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include'
CPP='/usr/local/gfortran/bin/gcc -E'
CPPFLAGS='-falign-functions=64 -Wall -g -O2 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include'
CXX='/usr/local/gfortran/bin/g++'
CXXCPP='/usr/local/gfortran/bin/g++ -E'
CXXFLAGS='-falign-functions=64 -Wall -g -O2'
DEFS='-DHAVE_CONFIG_H'
ECHO_C='\c'
ECHO_N=''
ECHO_T=''
EGREP='/usr/bin/grep -E'
EXEEXT=''
FC='/usr/local/gfortran/bin/gfortran'
FCFLAGS='-Wall -g -O2'
GLPK_LIBS=''
GMP_LIBS=''
GREP='/usr/bin/grep'
HAVE_GLPK='0'
HAVE_GMP='0'
HAVE_LIBXML='1'
LDFLAGS=''
LIBOBJS=''
LIBS=''
LTLIBOBJS=''
OBJEXT='o'
PACKAGE_BUGREPORT='csardi.gabor@gmail.com'
PACKAGE_NAME='igraph'
PACKAGE_STRING='igraph 1.2.6'
PACKAGE_TARNAME='igraph'
PACKAGE_URL=''
PACKAGE_VERSION='1.2.6'
PATH_SEPARATOR=':'
SHELL='/bin/sh'
XML2CONFIG='/usr/bin/xml2-config'
XML2_CFLAGS='-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include'
XML2_LIBS='-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -lxml2 -lz -lpthread -licucore -lm'
ac_ct_CC='/usr/local/gfortran/bin/gcc'
ac_ct_CXX=''
ac_ct_FC=''
bindir='${exec_prefix}/bin'
build_alias=''
datadir='${datarootdir}'
datarootdir='${prefix}/share'
docdir='${datarootdir}/doc/${PACKAGE_TARNAME}'
dvidir='${docdir}'
exec_prefix='${prefix}'
host_alias=''
htmldir='${docdir}'
includedir='${prefix}/include'
infodir='${datarootdir}/info'
libdir='${exec_prefix}/lib'
libexecdir='${exec_prefix}/libexec'
localedir='${datarootdir}/locale'
localstatedir='${prefix}/var'
mandir='${datarootdir}/man'
oldincludedir='/usr/include'
pdfdir='${docdir}'
prefix='/usr/local'
program_transform_name='s,x,x,'
psdir='${docdir}'
sbindir='${exec_prefix}/sbin'
sharedstatedir='${prefix}/com'
sysconfdir='${prefix}/etc'
target_alias=''

[...]

configure: exit 0

@jankowtf
Copy link

jankowtf commented Oct 12, 2021

@ntamas & @szhorvat (and everyone that contributed before that): thank you guys SOOO much! You so made my day as this ends a 14 day-long struggle to get this to work on my macOS ARM!

FOSS and its community FTW 🚀💪

@ntamas
Copy link
Member

ntamas commented Oct 13, 2021

Apparently there are still a couple of warnings and errors even though the build went through per se 👉 should these bother me?

No, these are fine - the C core was released quite a long while ago, and newer compilers tend to be pickier than older ones so there are a few warnings that did not appear before.

@ntamas ntamas closed this as completed Oct 16, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests