I have been trying to install the "kernlab" package as I am trying to learn machine learning and need it for Support Vector Machine models. I have GCC-13 downloaded through Homebrew, and it is stored in /opt/homebrew/opt (which I know is a non-typical location for it to download to). I have also made my own Makevars file aligning with Rodrigo Zepeda's blog (https://rodzepeda.medium.com/fixing-macos-catalinas-mess-when-trying-to-compile-almost-any-r-package-d94a063d64eb). I do have MacOS Sonoma 14.4.1 (the newest version), RStudio/2024.04.0+735 and gcc-13. However, when I go to install the package, I get this error:
> install.packages("kernlab")
Warning in install.packages :
unable to access index for repository http://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1:
cannot open URL 'http://cran.rstudio.com/bin/macosx/big-sur-arm64/contrib/4.1/PACKAGES'
Package which is only available in source form,
and may need compilation of C/C++/Fortran:
‘kernlab’
Do you want to attempt to install these from sources? (Yes/no/cancel) Y
installing the source package ‘kernlab’
trying URL 'http://cran.rstudio.com/src/contrib/kernlab_0.9-32.tar.gz'
Content type 'application/x-gzip' length 1215773 bytes (1.2 MB)
==================================================
downloaded 1.2 MB
* installing *source* package ‘kernlab’ ...
** package ‘kernlab’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
/opt/homebrew/opt/llvm/bin/clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I/opt/homebrew/opt/icu4c/include -I/opt/homebrew/opt/libxml2/include -I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/libpng/include/ -I/opt/homebrew/opt/gettext/include -I/opt/homebrew/opt/llvm/include -I/opt/homebrew/opt/openblas/include -I/opt/homebrew/opt/lapack/include -I/opt/homebrew/opt/tcl-tk/include -I/opt/homebrew/opt/udunits/include/ -I/opt/homebrew/opt/expat/include -I/opt/homebrew/opt/krb5/include -I/opt/homebrew/opt/libpq/include -I/opt/homebrew/opt/qt@5/include -fPIC -falign-functions=64 -Wall -g -O2 -c brweight.cpp -o brweight.o
In file included from brweight.cpp:41:
In file included from ./brweight.h:42:
In file included from ./errorcode.h:42:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/iostream:43:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/ios:223:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__locale:15:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__memory/shared_ptr.h:24:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__memory/allocation_guard.h:15:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__memory/allocator_traits.h:14:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__memory/construct_at.h:23:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/new:364:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/cstdlib:87:
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:145:30: error: unknown type name 'ldiv_t'
145 | inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); }
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:145:82: error: no member named 'ldiv' in the global namespace
145 | inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); }
| ~~^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:147:30: error: unknown type name 'lldiv_t'
147 | inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); }
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/stdlib.h:147:93: error: no member named 'lldiv' in the global namespace
147 | inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); }
| ~~^
In file included from brweight.cpp:41:
In file included from ./brweight.h:42:
In file included from ./errorcode.h:42:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/iostream:43:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/ios:223:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__locale:15:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__memory/shared_ptr.h:33:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__memory/unique_ptr.h:17:
/opt/homebrew/opt/llvm/bin/../include/c++/v1/__functional/hash.h:40:8: error: reference to unresolved using declaration
40 | std::memcpy(&__r, __p, sizeof(__r));
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/cstring:80:1: note: using declaration annotated with 'using_if_exists' here
80 | using ::memcpy _LIBCPP_USING_IF_EXISTS;
| ^
In file included from brweight.cpp:41:
In file included from ./brweight.h:42:
In file included from ./errorcode.h:42:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/iostream:43:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/ios:223:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__locale:16:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__mutex/once_flag.h:21:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/tuple:272:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/compare:145:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__compare/compare_partial_order_fallback.h:13:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__compare/partial_order.h:14:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__compare/weak_order.h:14:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/__compare/strong_order.h:20:
In file included from /opt/homebrew/opt/llvm/bin/../include/c++/v1/cmath:319:
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:392:31: error: use of undeclared identifier 'FP_NAN'
392 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:392:39: error: use of undeclared identifier 'FP_INFINITE'
392 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:392:52: error: use of undeclared identifier 'FP_NORMAL'
392 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:392:63: error: use of undeclared identifier 'FP_SUBNORMAL'
392 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:392:77: error: use of undeclared identifier 'FP_ZERO'
392 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:397:31: error: use of undeclared identifier 'FP_NAN'
397 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:397:39: error: use of undeclared identifier 'FP_INFINITE'
397 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:397:52: error: use of undeclared identifier 'FP_NORMAL'
397 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:397:63: error: use of undeclared identifier 'FP_SUBNORMAL'
397 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:397:77: error: use of undeclared identifier 'FP_ZERO'
397 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:402:31: error: use of undeclared identifier 'FP_NAN'
402 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:402:39: error: use of undeclared identifier 'FP_INFINITE'
402 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:402:52: error: use of undeclared identifier 'FP_NORMAL'
402 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
/opt/homebrew/opt/llvm/bin/../include/c++/v1/math.h:402:63: error: use of undeclared identifier 'FP_SUBNORMAL'
402 | return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, __x);
| ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [brweight.o] Error 1
ERROR: compilation failed for package ‘kernlab’
* removing ‘/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/kernlab’
Warning in install.packages :
installation of package ‘kernlab’ had non-zero exit status`
So far I have not been able to find any information on how to fix this.
So far, I have uninstalled and reinstalled gcc using Homebrew. I also tried to install gcc without Homebrew but it wasn't very successful for me as it resulted in even more errors and more confusion over the files in Terminal. When I reinstalled gcc and followed along a second time with Rodrigo's forum, I went back to the same errors I was having (as above).
It is my first time asking a question in an online forum, so if there is anything I have missed please don't hesitate to let me know. If you need more information that is fine too. I just really want to get this solved!
Perhaps following this one may help: https://yiqingxu.org/public/BigSurError.pdf
If you have already done those steps, sorry for pointing it out. I saw that sometimes the errors envolving gcc on Mac is solved by installing XCode with support to OpenMP. I don't know if this may be the case, but maybe it's worth trying out:
curl -O https://mac.r-project.org/openmp/openmp-12.0.1-darwin20-Release.tar.gz && sudo tar fvxz openmp-12.0.1-darwin20-Release.tar.gz -C / && mkdir -p ~/.R && echo -e "CPPFLAGS += -Xclang -fopenmp\nLDFLAGS += -lomp" >> ~/.R/Makevars
I also had a hard time trying to compile R Packages which requires gcc on MacOS, so if those don't fix the problem and you figure out, please let me know