How to install gfortran for MacOS Monterey (version 12.2.1) M1? - gfortran

I am trying to install Fortran on my MacBook MacOS Monterey (version 12.2.1) M1 chip laptop. I downloaded and installed the gfortran from this website (gfortran 12-Dec 18, 2021): https://github.com/fxcoudert/gfortran-for-macOS/releases with no issues.
I then followed the instructions on this link: https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/ and when following the steps to do a 'quick check' with C++, I receive these errors:
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_3.so] Error 1
I attempted to solve the issue by inputted this command in terminal:
ln -s /usr/local/gfortran /opt/R/arm64
But I received a "Permission denied" output.
There may be issues with installing gfortran on Monterey M1 chip, but I think the main problem is where my gfortran is located on my laptop. I am not sure. Does anyone have a solution as to how to relocate gfortran on my laptop through Terminal?
Much appreciated.

Have you tried to install and update XCode Command Line Tools? In principle, it comes with gcc and gfortran. Once installed, you do not need to use directly XCode to run gfortran on a terminal. XCode is available from the app store.
You can also install gcc (which contain gfortran) via brew brew install gcc.

Related

Espressif tool chain broken after macOS Monterey 12.3 beta 3 install

After Monterey 12.3 beta 2 installed, the Espressif tool chain is broken. If you compile with platformIO you'll get the following error:
^
Linking .pio/build/esp32dev/firmware.elf
/Users/stephanedeluca/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/5.2.0/../../../../xtensa-esp32-elf/bin/ld: /Users/stephanedeluca/.platformio/packages/toolchain-xtensa32/bin/../libexec/gcc/xtensa-esp32-elf/5.2.0/liblto_plugin.so: error loading plugin: dlopen(/Users/stephanedeluca/.platformio/packages/toolchain-xtensa32/bin/../libexec/gcc/xtensa-esp32-elf/5.2.0/liblto_plugin.so, 0x0002): Library not loaded: /opt/osxcross/target/bin/../x86_64-apple-darwin12/lib/libstdc++.6.dylib
Referenced from: /Users/stephanedeluca/.platformio/packages/toolchain-xtensa32/libexec/gcc/xtensa-esp32-elf/5.2.0/liblto_plugin.0.so
Reason: tried: '/opt/osxcross/target/bin/../x86_64-apple-darwin12/lib/libstdc++.6.dylib' (no such file)
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32dev/firmware.elf] Error 1
Looking at my Mac, there is no /opt/osxcross.
I have searched on another Mac with the beta 1 where the tool chain was still working the presence of the folder, and guess what?! there's none!
Any idea what as actually broken by the beta?
Finally, here is a work around: we are going to provide the missing /opt/osxcross folder and contents.
If you do not have gcc installed (this should be unlikely though, install gcc to get the folder content, as follows:
$ brew install gcc
Create the missing /opt/osxcross folder as follows:
$ sudo mkdir -p /opt/osxcross/target/bin/../x86_64-apple-darwin12/lib/
Note that you'll be prompted for your password.
And, finally, copy the folder contents from the gcc build as follows:
$ sudo cp /usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11/libstdc++.6.dylib /opt/osxcross/target/x86_64-apple-darwin12/lib/libstdc++.6.dylib
This completes the fix.
You must restart vscode, Arduino IDE or whatever tool you use. And then build your project, which should compile successfully.
And voila.

Clang Error Raised When Compiling Using AVR-GCC on Mac OS

I am trying to cross compile a program for an AVR using avr-gcc that I installed through macports. In the terminal:
avr-gcc -O1 -DF_CPU=1000000UL -DBAUD=9600 -I. -I/opt/local/avr/include/ -Wl,-Map,main.map -mmcu=atmega328p main.c -c
which results in the errors:
clang: error: unknown argument: '-mgcc-isr'
clang: error: unknown argument: '-mno-skip-bug'
The above cross compile used to work but after updating to Catalina and reinstalling avr-gcc something has gotten messed up. Searching google I have found that, with newer versions of Clang, if Clang doesn't recognize the command line argument then it raises an error. The suggestions said to use something like -Wno-error=gcc-isr. So my command becomes:
avr-gcc -O1 -Wno-error=gcc-isr -DF_CPU=1000000UL -DBAUD=9600 -I. -I/opt/local/avr/include/ -Wl,-Map,main.map -mmcu=atmega328p main.c -c
which results in:
cc1: error: ‘-Werror=gcc-isr’: no option -Wgcc-isr
It looks like something is getting messed up between Clang and avr-gcc. Although I'm not sure why Clang gets called when I am using avr-gcc. Does anyone have any idea what's going on here?
Ok, I'm not sure why clang gets called with avr-gcc but I did manage to get the code to compile by uninstalling: (1) avr-gcc and (2) avr-binutils through macports using:
sudo port uninstall avr-binutils
sudo port uninstall avr-libc (I uninstalled this because it depends on avr-gcc)
sudo port uninstall avr-gcc
then I reinstalled it using
sudo port install avr-gcc
which asked if I wanted install avr-binutils. I then reinstalled avr-libc. These are the direct steps. I made a mistake by hitting 'N' when it asked me if I wanted to install avr-binutils. So I had add:
sudo port clean avr-binutils
to clear that error. Once that was cleared I could follow the above steps. Again, this cleared the error by just reinstalling the cross compiling software but I still think there is some underlying misunderstanding of the original problem.
I ran into the same issue while I was trying to compile a keyboard firmware that runs on an atmega32 microcontroller and I had to rebuild avr-gcc locally to fix things.
While the accepted solution did not work for me - I got the same error again
clang: error: unknown argument: '-mgcc-isr'
clang: error: unknown argument: '-mno-skip-bug'
What did work for me was to first uninstall avr-binutils and avr-gcc like so
brew uninstall --ignore-dependencies avr-binutils
brew uninstall --ignore-dependencoes avr-gcc#9
and then reinstall avr-binutils
brew install avr-binutils
Instead of simply reinstalling avr-gcc, install from source like so
brew install --build-from-source avr-gcc#9

How do I install rpy2 when clang doesn't support OpenMP (Mac OSX)?

I am trying to use pip to install rpy2 on OSX 10.12.5. I get this error:
clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
error: command '/usr/bin/clang' failed with exit status 1
From what I understand, this is because my version of clang does not support OpenMP. Using homebrew, I installed LLVM 8.1.0 (clang 802.0.42), but now I need to update clang to support OpenMP. Can anyone give me detailed instructions of how to go about this? I am not understanding the other sources I am reading online.
I just got rpy2-2.9.0 to install via pip on Mac OSX 10.13, after getting the same error you reported, by downgrading to R 3.3.3, downloaded from https://cran.r-project.org/bin/macosx/. I just re-installed R 3.3.3 then re-ran 'pip install rpy2' and it installed fine.

Building libxml2-2.9.2 on OS X Yosemite, xCode 6

I have an xcode project which uses xmppframework.
the KissXML module of this framework needs libxml2, according to https://github.com/robbiehanson/KissXML/wiki/GettingStarted.
I followed these instructions, and downloaded libxml2 from ftp://xmlsoft.org/libxml2/.
Specifically, I downloaded and extracted LATEST_LIBXML2, which turns out to be libxml2-2.9.2.
I then added the relevant header search path to my xcode project, and
-l "lxml2"
to my linker flags.
However, when I build my project, it gives the following linker error:
ld: library not found for -llxml2
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I suspect this is because I need to build libxml2 myself, in order to get the library binary. However, I can't find specific instructions for doing this on OS X Yosemite, xcode 6.
Does anyone have any instructions on building libxml2-2.9.2 on OS X Yosemite, Xcode 6, so that I can link to it in my project?
Alternatively, if someone can provide a binary for libxml2-2.9.2, that might also work. I did find http://www.explain.com.au/oss/libxml2xslt.html#id2658905, but this guy only seems to offer binaries for older versions of libxml2, not the current version.
Thanks!
Best regards,
Chris
Well firstly, the library is called libxml2, so the link should be -lxml2 and not -llxml2.
Secondly, there is already a libxml2 built-in to OSX/iOS, and you can actually reference that library in the link libraries section for the project. You generally don't need to build the library unless you really want newer features of the newer version.
In the General tab of the project, use the Linked frameworks and Libraries to add a reference to libxml2.dylib.
The instructions on the page you reference are using the version of libxml2 that is available on OSX/iOS already. You do not need to download libxml2 to get it to work.
The location that's mentioned /usr/include/libxml2 on the page will work for you also if you install the command line developer tools - at a terminal prompt do xcode-select --install.
I have built LibXML2 (latest version 2.9.2) on Solaris SPARC, Linux and Windows. I have never use MacOS (poor =)) ).
Here's my brief instruction. You can try the similar way.
cd /opt/mydir/libxml2
mkdir linux-gcc3
gunzib -c libxml2-2.9.2.tar.gz | tar xvf –
cd libxml2-2.9.2
./configure --prefix=/opt/mydir/libxml2/linux-gcc3 --enable-static --disable-shared 2>&1 | tee conf.log
## 64 bit
## ./configure CC="cc -m64" --prefix=/opt/mydir/libxml2/linux-gcc3 --enable-static --disable-shared 2>&1 | tee conf.log
make 2>&1 | tee make.log
make install

pip installing ipython with readline on OSX Lion

What is required to get ipython fully functional on OSX Lion? I'm trying to get ipython with readline working and having no success.
My approach:
(inside a virtual environment)
pip install ipython # runs, but only slightly useful because can't indent blocks
pip install readline
The second completes with warnings and eventually says "Successfully installed readline"
But I'm still left without the ability to indent blocks and going back in the command history leads to garbled terminal output.
I suspect these warnings are critical, but I'm at a loss about what to do about them.
ld: warning: ignoring file readline/libreadline.a, file was built for archive which is not the architecture being linked (i386)
ld: warning: ignoring file readline/libhistory.a, file was built for archive which is not the architecture being linked (i386)
(I've spent the morning googling the errors, to no avail)
tia,
I've had the same issue and for some reason only the version of readline installed via easy_install readline works fine.
1) Upgraded to latest Mac OS X dev tools
2) Installed Distribute
3) pip install ipython
4) pip install readline
Thanks to this article.

Resources