admin管理员组文章数量:1403455
I was trying to brush up my RCpp skills and attempted to use sourceCpp() to use a simple hello_world.cpp program.
However, I encounter
ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0' not found
ld: library 'gfortran' not found
But there is an installed fortran:
GNU Fortran (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
Recent Update 21/03/2025
I reinstalled R and Studio, through home-brew. Rcpp package seems to be working. But when I try RcppArmadillo. It is showing the fortran not found.
Final Update 22/03/2025
Got the location of fortran by "system("which gfortran")" and
edited FC and FLIBS to that location in the file opened by "file.edit(file.path(R.home("etc"), "Makeconf"))"
I was trying to brush up my RCpp skills and attempted to use sourceCpp() to use a simple hello_world.cpp program.
However, I encounter
ld: warning: search path '/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0' not found
ld: library 'gfortran' not found
But there is an installed fortran:
GNU Fortran (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
Recent Update 21/03/2025
I reinstalled R and Studio, through home-brew. Rcpp package seems to be working. But when I try RcppArmadillo. It is showing the fortran not found.
Final Update 22/03/2025
Got the location of fortran by "system("which gfortran")" and
edited FC and FLIBS to that location in the file opened by "file.edit(file.path(R.home("etc"), "Makeconf"))"
Share Improve this question edited Mar 22 at 11:15 FAM asked Mar 21 at 6:50 FAMFAM 1136 bronze badges 6 | Show 1 more comment1 Answer
Reset to default 1Poking enviornment variables (I guess not so good)
Since your address starts with /opt/gfortran/...
- I have all my fortran addresses starting with /opt/homebrew/...
.
Sys.getenv()
:
F77 /opt/homebrew/Caskroom/miniconda/base/envs/R441/bin/arm64-apple-darwin20.0.0-gfortran
F90 /opt/homebrew/Caskroom/miniconda/base/envs/R441/bin/arm64-apple-darwin20.0.0-gfortran
F95 /opt/homebrew/Caskroom/miniconda/base/envs/R441/bin/arm64-apple-darwin20.0.0-gfortran
FC /opt/homebrew/Caskroom/miniconda/base/envs/R441/bin/arm64-apple-darwin20.0.0-gfortran
FC_FOR_BUILD /opt/homebrew/Caskroom/miniconda/base/envs/R441/bin/arm64-apple-darwin20.0.0-gfortran
FFLAGS -march=armv8.3-a -ftree-vectorize -fPIC
-fno-stack-protector -O2 -pipe -isystem
/opt/homebrew/Caskroom/miniconda/base/envs/R441/include
FORTRANFLAGS -march=armv8.3-a -ftree-vectorize -fPIC
-fno-stack-protector -O2 -pipe -isystem
/opt/homebrew/Caskroom/miniconda/base/envs/R441/include
GFORTRAN /opt/homebrew/Caskroom/miniconda/base/envs/R441/bin/arm64-apple-darwin20.0.0-gfortran
I had installed my R in this case into a conda environment - so the gfortran is in the environment binary folder. And the library flags are to the conda environment's include
folder.
Theoretically one could the environment variables in R like this:
Sys.setenv(GFORTRAN = "/path/from/your/which gfortran command", FFLAGS = "path to your include for fortran")
etc.
But I think the problem is better solved by a proper installation.
Actually, if you install R, fortran is installed.
probably a .libPaths() problem?
Probably your R looks for other additional library folders than it should?
Check .libPaths()
. If it lists folders which should not be looked into,
you can exclude folders by building a vector containing only the folders which you want. E.g. let's say it lists 3 folders and you want only 1 and 2:
.libPaths(.libPaths()[c(1, 2)], include.site=FALSE)
the include.site=FALSE
makes that only those chosen paths stay in .libPaths()
.
This should be done in a fresh session right at the beginning of the session.
If you now load libraries, R looks only into those folders for the libraries you load.
Sometimes dotfiles in your environment like .Rprofile
define library paths. And you can put this code into your local environment's .Rprofile
file which gets run everytime you start a session. Check also your .Renviron
file which defines environment variables.
本文标签: macosRcppArmadillo39gfortran39 not foundMAC M3Sonoma 145Stack Overflow
版权声明:本文标题:macos - RcppArmadillo : 'gfortran' not found , MAC M3, Sonoma 14.5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744369996a2602973.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
which gfortran
give in your terminal? - I guess you might need some environmental variable set up for this. – Gwang-Jin Kim Commented Mar 21 at 9:19Sys.getenv()
to list all environmental variables. – Gwang-Jin Kim Commented Mar 21 at 9:23FC
andFLIBS
was the problem, you could add a fix at the start of.Rprofile
either in your home folder or locally - so that this code gets executed as soon as you start your R session. - In this way, in future - on your machine - you don't have to enter this correcting code again and again. Or in your ~/.bashrc add these new environmental variables (eventually) - but before overwriting, save the original variables under a different name - so that you can recover them, whenever you need them back. (Not that you break other processes which need them like they are set). – Gwang-Jin Kim Commented Mar 22 at 15:24~/.R/Makeconf
. I think all this is described here: blog.thecoatlessprofessor/programming/cpp/… – Ada Lovelace Commented Mar 22 at 21:56