I have an Apple M1 Pro and I am using Rosetta in the terminal. I have Rosetta checked when using the terminal, but I don't know if Rosetta is being applied.
I am not sure if Rosetta is applied or not.
Specifically, when Resetta is checked, I get the following results.
arch
arm64
uname -m
arm64
On the other hand, when Resetta is not checked, the result is as follows.
arch
i386
uname -m
arm64
I thought that uname -m was expected to show x86_64, but it only shows arm64, is there something wrong with the setting?
Solved. The setting of .zshrc is invalid.
Related
I'm trying to use packages that require Rcpp in R on my M1 Mac, which I was never able to get up and running after purchasing this computer. I updated it to Monterey in the hope that this would fix some installation issues but it hasn't. I tried running the Rcpp check from this page but I get the following error:
> Rcpp::sourceCpp("~/github/helloworld.cpp")
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0'
ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_4.so] Error 1
clang++ -arch arm64 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include -I"/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/RcppArmadillo/include" -I"/Users/afredston/github" -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c helloworld.cpp -o helloworld.o
clang++ -arch arm64 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o sourceCpp_4.so helloworld.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.2.0/11.0.0 -L/opt/R/arm64/gfortran/lib -lgfortran -lemutls_w -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in Rcpp::sourceCpp("~/github/helloworld.cpp") :
Error 1 occurred building shared library.
I get that it can't "find" gfortran. I installed this release of gfortran for Monterey. When I type which gfortran into Terminal, it returns /opt/homebrew/bin/gfortran. (Maybe this version of gfortran requires Xcode tools that are too new—it says something about 13.2 and when I run clang --version it says 13.0—but I don't see another release of gfortran for Monterey?)
I also appended /opt/homebrew/bin: to PATH in R so it looks like this now:
> Sys.getenv("PATH")
[1] "/opt/homebrew/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/Applications/RStudio.app/Contents/MacOS/postback"
Other things I checked:
Xcode command line tools is installed (which clang returns /usr/bin/clang).
Files ~/.R/Makevars and ~/.Renviron don't exist.
Here's my session info:
R version 4.1.1 (2021-08-10)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.1.1 tools_4.1.1 RcppArmadillo_0.10.7.5.0
[4] Rcpp_1.0.7
Background
Currently (2023-02-20), CRAN builds R 4.2 binaries for Apple silicon using Apple clang from Command Line Tools for Xcode 13.1 and using an experimental fork of GNU Fortran 12.
If you obtain R from CRAN (i.e., here), then you need to replicate CRAN's compiler setup on your system before building R packages that contain C/C++/Fortran code from their sources (and before using Rcpp, etc.). This requirement ensures that your package builds are compatible with R itself.
A further complication is the fact that Apple clang doesn't support OpenMP, so you need to do even more work to compile programs that make use of multithreading. You could circumvent the issue by building R itself and all R packages from sources with LLVM clang, which does support OpenMP, but that approach is onerous and "for experts only".
There is another approach that has been tested by a few people, including Simon Urbanek, the maintainer of R for macOS. It is experimental and also "for experts only", but it works on my machine and is much simpler than learning to build R yourself.
Instructions for obtaining a working toolchain
Warning: These come with no warranty and could break at any time. Some level of familiarity with C/C++/Fortran program compilation, Makefile syntax, and Unix shells is assumed. Everyone is encouraged to consult official documentation, which is more likely to be maintained than answers on SO. As usual, sudo at your own risk.
I will try to address compilers and OpenMP support at the same time. I am going to assume that you are starting from nothing. Feel free to skip steps you've already taken, though you might find a fresh start helpful.
I've tested these instructions on a machine running Big Sur, and at least one person has tested them on a machine running Monterey. I would be glad to hear from others.
Download an R 4.2 binary from CRAN here and install. Be sure to select the binary built for Apple silicon.
Run
$ sudo xcode-select --install
in Terminal to install the latest release version of Apple's Command Line Tools for Xcode, which includes Apple clang. You can obtain earlier versions from your browser here. However, the version that you install should not be older than the one that CRAN used to build your R binary.
Download the gfortran binary recommended here and install by unpacking to root:
$ curl -LO https://mac.r-project.org/tools/gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz
$ sudo tar xvf gfortran-12.0.1-20220312-is-darwin20-arm64.tar.xz -C /
$ sudo ln -sfn $(xcrun --show-sdk-path) /opt/R/arm64/gfortran/SDK
The last command updates a symlink inside of the gfortran installation so that it points to the SDK inside of your Command Line Tools installation.
Download an OpenMP runtime suitable for your Apple clang version here and install by unpacking to root. You can query your Apple clang version with clang --version. For example, I have version 1300.0.29.3, so I did:
$ curl -LO https://mac.r-project.org/openmp/openmp-12.0.1-darwin20-Release.tar.gz
$ sudo tar xvf openmp-12.0.1-darwin20-Release.tar.gz -C /
After unpacking, you should find these files on your system:
/usr/local/lib/libomp.dylib
/usr/local/include/ompt.h
/usr/local/include/omp.h
/usr/local/include/omp-tools.h
Add the following lines to $(HOME)/.R/Makevars, creating the file if necessary.
CPPFLAGS += -I/usr/local/include -Xclang -fopenmp
LDFLAGS += -L/usr/local/lib -lomp
Run R and test that you can compile a program with OpenMP support. For example:
if (!requireNamespace("RcppArmadillo", quietly = TRUE))
install.packages("RcppArmadillo")
Rcpp::sourceCpp(code = '
#include <RcppArmadillo.h>
#ifdef _OPENMP
# include <omp.h>
#endif
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
void omp_test()
{
#ifdef _OPENMP
Rprintf("OpenMP threads available: %d\\n", omp_get_max_threads());
#else
Rprintf("OpenMP not supported\\n");
#endif
}
')
omp_test()
OpenMP threads available: 8
If the C++ code fails to compile, or if it compiles without error but you get linker warnings or you find that OpenMP is not supported, then one of us has probably made a mistake. Please report any issues.
References
Everything is a bit scattered:
R Installation and Administration manual [link]
R for macOS Developers page [link]
I resolved this issue by adding a path to the homebrew installation of gfortran to my ~/.R/Makevars following these instructions: https://pat-s.me/transitioning-from-x86-to-arm64-on-macos-experiences-of-an-r-user/#gfortran
I just avoided the issue until MacOS had things working more smoothly. so I either Windows Developer Virtual Machine (VM) or run my code development in another environment. I'm not too impressed with the updated and "faster" chipset, but that it doesn't work with much. Slow to implement and work-a-rounds often are a must.
Tested the following process for making multithread data.table work in a M2 MacBook Pro (macOS Monterey)
Steps are mostly the same with this answer by the user inferator.
Download and install R from CRAN
Download and install RStudio with developer tools
Run the following commands in terminal to install OpenMP
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 /
Add compiler flags to connect clan w/ OpenMP. In terminal, write the following:
cd ~
mkdir .R
nano .R/Makevars
Inside the opened Makevars file paste the following lines. Once finished, hit command+O and then Enter to save. Do a command+X to close the editor.
CPPFLAGS += -Xclang -fopenmp
LDFLAGS += -lomp
Download and run the installer for gfortran by downloading gfortran-ARM-12.1-Monterey.dmg from the respective GitHub repo
This concludes the steps regarding enabling OpenMP and (hopefully) Rcpp in R under a M2 chip system.
Now, for testing that everything works with data.table I did the following
Open RStudio and run
install.packages("data.table", type = "source")
If everything is done correctly, the package should compile without any errors and return the following when running getDTthreads(verbose = TRUE):
OpenMP version (_OPENMP) 201811
omp_get_num_procs() 8
R_DATATABLE_NUM_PROCS_PERCENT unset (default 50)
R_DATATABLE_NUM_THREADS unset
R_DATATABLE_THROTTLE unset (default 1024)
omp_get_thread_limit() 2147483647
omp_get_max_threads() 8
OMP_THREAD_LIMIT unset
OMP_NUM_THREADS unset
RestoreAfterFork true
data.table is using 4 threads with throttle==1024. See ?setDTthreads.
[1] 4
As I have no time for configuring arm g++ cross compiler on my i686 debian machine, I decided to install graphic mode on my BeagleBone which runs on Debian. Does arm g++ compiler exists for debian BBB distribution? I just wanted to skip cross-compiling and build my code on BBB, and run it immediately after it is compiled. I'm looking for answers if that is possible, or cross-compiling is necessary thing in this situation?
There are g++ compilers for the following architectures:
amd64 arm64 armel armhf i386 mips mipsel powerpc ppc64el s390x
See https://packages.debian.org/search?keywords=g%2B%2B. If you are running plain arm and the two highlighted architectures don't fit the bill, you're out of luck.
I'm facing some issues on compiling gcc on solaris 10.
I downloaded the source code from "ftp://ftp.gwdg.de/pub/misc/gcc/releases/gcc-4.1.2/" and tried to compile it, by using configure and then make.
But the make stops at line mentioned below.
perl ../.././fastjar/../contrib/texi2pod.pl -D fastjar > fastjar.pod
I'hv checked perl is already installed but it has stuck at this point for more than 12hrs.
gcc version already installed is 3.4.3
perl version is 5.8.4
The above problem is solved as i used ksh shell to build/configure it, but i ran into another problem i.e. the gcc which i got after this build says
warning: visibility attribute not supported in this configuration; ignored
This visibility feature is required as i don't want to export all of my function in my shared libraries.
According to this link the waring is due to objdump which it says is not present in my $PATH. But i checked it is in $PATH variable.
Thanks
Here is how i solved this problem:
Installed gnu binutils version 2.18 using gcc 3.4.3(available in solaris by default).
cd gcc_source_dir
mkdir objdir && cd objdir
../configure --with-gnu-as --with-as=/binutils_2_18/bin/as --with-gnu-ld --with-ld=/binutils_2_18/bin/ld --prefix=$PREFIX --enable-threads=posix --enable-checking=release --with-system-zlib --enable-shared --disable-symvers --enable-languages=c,c++
gmake
gmake install
I'm having problems installing QT on my MacBook with Lion 10.7.3 and XCode 4.3.1 installed. I tried to install with brew, and got a compiler error. Below is the end of the error, and the "brew doctor" output. It seems to be using the wrong version of gcc... although I just installed the latest XCode. Any ideas? I'm trying to install QT, so I can run headless browser tests with capybara-webkit. (I also tried with --install-from-source and got the same error.)
gstroup$ brew install qt
....
kernel/qcocoaview_mac.mm:1386:61: error: cannot initialize a parameter of type 'NSString *' with an lvalue of type 'const NSString *'
return [[[NSAttributedString alloc] initWithString:tmpString] autorelease];
^~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:28:34: note: passing argument to parameter 'str' here
- (id)initWithString:(NSString )str;
^
2 errors generated.
make[2]: [.obj/release-shared/qcocoaview_mac.o] Error 1
make[1]: [release] Error 2
make: ** [sub-gui-make_default-ordered] Error 2
==> Exit Status: 2
http://github.com/mxcl/homebrew/blob/master/Library/Formula/qt.rb#L76
==> Environment
/usr/bin/gcc
HOMEBREW_VERSION: 0.8
HEAD: 64e489663add868db679cca2186ff8d7796e5d9e
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
HOMEBREW_REPOSITORY: /usr/local
HOMEBREW_LIBRARY_PATH: /usr/local/Library/Homebrew
Hardware: 8-core 64-bit dunno
OS X: 10.7.3
Kernel Architecture: x86_64
Ruby: 1.8.7-249
/usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
Xcode: 4.3.1
GCC-4.0: N/A
GCC-4.2: build 401 (5664 or newer recommended)
LLVM: build 2336
MacPorts or Fink? false
X11 installed? true
==> Build Flags
CC: /usr/bin/cc => /usr/bin/clang
CXX: /usr/bin/c++ => /usr/bin/clang
LD: /usr/bin/cc => /usr/bin/clang
CFLAGS: -O3 -w -pipe
CXXFLAGS: -O3 -w -pipe -fvisibility=hidden
MAKEFLAGS: -j8
Error: Failed executing: make
Please report this bug: https://github.com/mxcl/homebrew/wiki/new-issue
Also try:
brew doctor to check your setup for common problems.
brew missing to check installed packages for missing deps.
gstroup$ brew doctor
/usr/bin/gcc
Your gcc 4.2.x version is older than the recommended version. It may be advisable
to upgrade to the latest release of Xcode.
We couldn't detect gcc 4.0.x. Some formulae require this compiler.
/usr/bin is in your PATH before Homebrew's bin. This means that system-
provided programs will be used before Homebrew-provided ones. This is an
issue if you install, for instance, Python.
Consider editing your .bashrc to put:
/usr/local/bin
ahead of /usr/bin in your $PATH.
Some brews install binaries to sbin instead of bin, but Homebrew's
sbin was not found in your path.
Consider editing your .bashrc to add:
/usr/local/sbin
to $PATH.
/usr/bin/gcc
gstroup$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)
Copyright (C) 2007 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.
Xcode 4.3.x switched away from gcc as the compiler. Now Apple uses llvm. This maybe the root of your issue. There is a Github project https://github.com/kennethreitz/osx-gcc-installer/downloads that will let you download a gcc compiler.
You may have to prefix your brew command with env CC=/usr/bin/gcc to specify the gcc compiler.
I am suddenly getting an sqlite3 error:
ActionView::Template::Error (dyld: Library not loaded: /usr/lib/libsqlite3.0.dylib
Referenced from: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CFNetwork.framework/Versions/A/CFNetwork
Reason: no suitable image found. Did find:
/usr/lib/libsqlite3.0.dylib: mach-o, but wrong architecture
/usr/local/lib/libsqlite3.0.dylib: mach-o, but wrong architecture
/usr/lib/libsqlite3.0.dylib: mach-o, but wrong architecture
I have no idea why I am suddenly getting this error. Rails 3.1.0 and Ruby 1.9.2 Mac OSX 10.5.8
Okay so this is a messed up sqlite3 install and it seems that lots of people run into this problem but solutions are a little hard to come by. After a lot of googling I did the following:
Step1: went to http://www.sqlite.org/download.html and downloaded sqlite-autoconf-3070800.tar.gz under source code
Step2: expand file and cd into the resultant directory
Step3: sudo CFLAGS='-arch i686 -arch x86_64' LDFLAGS='-arch i686 -arch x86_64' ./configure --disable-dependency-tracking
Step4: sudo make install
Step5: added /usr/local/lib to the path
I was doing an awful lot of tinkering during this time. It's possible that I have done something else along the way and not realized and not included it here. But these steps seemed to fix the problem for me.
My environment: Mac OSX 10.5.8 MacBookPro4, Intel Core 2 Duo, 2.5 GHz
Thank you so much, in my case I had to rearrange the parameters and I didn't use sudo to configure nor to make:
make clean
./configure --disable-dependency-tracking --prefix=/usr CFLAGS='-arch i686 -arch x86_64' LDFLAGS='-arch i686 -arch x86_64'
make
sudo make install
I didn't have to modify the path, I specified in the --prefix="my path"
Environment Mac OS X v.10.5.8 2GHz Intel Core 2 Duo
Exactly same problem but the solutions here didn't work for me.
Instead reinstalling sqlite3 gem fixed the problem for me.
Environment: Mac OS X v. 10.6.8, iMac