F951: Fatal Error - I need help to compile my first code (macOS 12.4)

That is correct, you should not execute exactly that command line. Or perhaps more correctly, if you do use it as written, it will have no effect because the existence test for the file will fail.

I have not used Homebrew on an intel mac, but I have read in the documentation that it uses a different set of install directories than the arm64 version. You can see this with your “which gfortran” results. My working theory is that your Clang error is the result of some missing element in PATH or in some other missing environment variable. Those are kind of technical things that are a standard part of programming in a unix/posix environment, they are not specific to gfortran or MacOS. So I was not suggesting that you figure out those details at this time, rather I was hoping that someone here who does use Homebrew on intel MacOS 11.x or 12.x on might know the details and could help you out. Once you have things working, then you can go back and learn exactly what PATH and other environment variables do.

The difference in the way Homebrew works is that on arm64 machines, all of the files are placed in the /opt/homebrew directory. But on intel machines, the files are placed in /usr/local. FYI, on my intel macs, I have used a different package manager, Fink, for over 20 years. Fink places its files in the /opt/sw directory rather than in /usr/local, which is one reason why I selected it all that time. However, Fink does not yet support the arm64 hardware, so on that one machine I am using Homebrew instead of Fink. My experience so far is that Homebrew works well and is easy to use, and I would have said the same thing about fink up until three years ago when the arm64 macs were introduced.

Thanks for the warning of not to use it, from the sounds of it it wouldn’t have done anything anyway, but as i am a total newbie when it comes to these things, i thought erring on the side of caution, before confirmation is no bad thing. Especially when i would be dealing with sudo stuff ( i know enough to know that can be dangerous).

I too would hope that someone on here can or at least point me in the right direction of fixing this clang error, seems odd that it’s not seeing it OSX 12.4 when it’s defo there, and perhaps you are right that it’s a PATH thing or MANPATH thing (whatever those are) and a home-brew person can see where the problem lies.

Again as in all things the solutions are many and just not one answer to any question, and i am sure that had i had known about Fink then perhaps i would have used that, there’s always the option of removing home-brew and installing Fink.

Can you actually compile a C program on your Mac?

// test.c
#include <stdio.h>
int main(void) { printf("Hello, World!\n"); return 0; }

Best test both clang and gcc (the latter is sometimes on Mac just clang).

clang test.c && ./a.out
gcc test.c && ./a.out

If this doesn’t work, you have to check your setup of the XCode command line tools again.

As Ron pointed out, there are different package managers for Mac around: Homebrew, MacPorts, Fink, or Conda. I’m personally a strong conda user since it is cross-platform package manager (I’m usually working on Linux, but distribute for Windows and MacOS as well). Choose whatever works best for you, they are all great package managers as long as they get the job done and don’t get into your way.


Ok, i would if i knew how to do that…i am a total newbie…you’re gonna have to walk me through it step by step…sorry guys…i am a little like my uncle was in the 80’s when he wanted his VCR programming to record the tv back in the day, they used to call me to do it, i wasn’t even a teenager! For me it was easy and logical for him it was a black box with a slot in the front. I feel a little like him at the moment, but i’m trying to remedy that. ( I got paid in tea and cake though!)

the C program above, has to be written in a text editor correct? I have Atom installed, do i need to have the C libraries for that installed too, or are they already installed?

the clang test and the gcc test are i assume after i’ve written the ‘code’ above in an editor and compiled it?

As for knowing what works best for me, well, i’m open to new suggestions, i have no bias or preference, again i just followed the tutorial on fortran-lang and just picked one…i could have easily chosen Macports as easily as Home brew.

Indeed, you already have a C compiler and libraries installed with your Fortran compiler. The error you are seeing is due to clang, the C compiler. If you are using atom, checkout the section here to install the terminal-tab extension, which allows you to open a terminal in your atom editor, than you don’t need to work with a separate terminal anymore.

Type in the code from above with atom, save the file as test.c, change to the terminal tab to invoke the commands to compile and execute. This should show you whether your C compiler works in the first place.

Although Fink is actively supported (new packages are added or modified daily), I think I would not recommend it right now. They are behind in supporting 11.x and 12.x and also arm64 hardware.

Regarding your Clang error, what happens when you type

which cc
cc --version

in a terminal window?

One other thing to try is Apple->System Preferences->Software Update or Apple->About This Mac->Software Update. It may be able to recognize if your command line tools are out of date and update them accordingly. This is the same way that you install security updates or OS upgrades on the Mac.

You should learn how to use a text editor. You can use vi in a terminal window. That is more or less the standard unix/posix text editor, but others are alright too. In unix, tools like this are supposed to be interchangable. I use emacs, which might be good eventually for you to look at, but it is more complicated than vi.

You can create the file and compile it in a terminal window with the following lines:

cat <<EOF > test.c
#include <stdio.h>
int main(void) { printf("Hello, World!\n"); return 0; }
clang test.c && ./a.out
gcc test.c && ./a.out

That uses what is called a “here document” in the shell to create the file. When you type those lines, you will see a “>” prompt for the three lines. That is alright. You can “cat test.c” afterwards to see what is in it if you want. Then those last two lines by @awvwgk compile and execute the code, all on one line, for the two compilers that you should have installed on your system. Both lines should print out the text the same way. The two compilers should be interchangeable tools. The line “cc test.c && ./a.out” should also work. The cc command is just another name for clang on a Mac.


wooooo…ok, here we go…thanks for the suggestion…this is what i get…(i found the info for the tab for terminal, thanks for that)…

The C code is in place, even saved it, and it looks pretty…colours and everything…:wink:

Opened up a terminal tab…and this is the result…(slightly redacted for personal info)

*For more info check out the docs: https://nuclide.io/docs/features/terminal*
*Error getting default shell:*
*ProcessExitError: "dscl" failed with exit code 185*
                                        <dscl_cmd> DS Error: -14009 (eDSUnknownNodeName)*

                                                                                      dscl . -read /Volumes/Wowcat Mac 1 Data/home UserShell*
*Error starting process:*
*Error: Cannot find module '/Volumes/Wowcat Mac 1 Data/home/.atom/packages/atom-ide-ui/node_modules/nuclide-prebuilt-libs/pty/build/pty-node-v80-darwin-x64/pty.node'*
*Require stack:*
*- /Volumes/Wowcat Mac 1 Data/home/.atom/packages/atom-ide-ui/node_modules/nuclide-prebuilt-libs/pty/lib/unixTerminal.js*
*- /Volumes/Wowcat Mac 1 Data/home/.atom/packages/atom-ide-ui/node_modules/nuclide-prebuilt-libs/pty/lib/index.js*
*- /Volumes/Wowcat Mac 1 Data/home/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-terminal/lib/pty-service/PtyService.js*
*- /Volumes/Wowcat Mac 1 Data/home/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-terminal/lib/AtomServiceContainer.js*
*- /Volumes/Wowcat Mac 1 Data/home/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-terminal/lib/terminal-view.js*
*- /Volumes/Wowcat Mac 1 Data/home/.atom/packages/atom-ide-ui/modules/atom-ide-ui/pkg/atom-ide-terminal/lib/main.js*
*- /Applications/Atom.app/Contents/Resources/app.asar/static/index.html*

so as you can see i didn’t even get to the stage where i can even start the compilation of the .c code.

HOWEVER…i did try the clang and gcc test in a normal terminal window after switching to the directory where the test.c code is and, guess what! It worked! woohoo…never mind my first FORTRAN code, but my first c code…Anyway, on the command line i got Hello World! so at least some thing works finally!

1 Like


Which cc comes up as /usr/bin/cc

and cc --version says, Apple clang version 11.0.3 (clang-1103.0.32.29)

Target: x86_64-apple-darwin21.5.0

Thread model: posix

InstalledDir: /Library/Developer/CommandLineTools/usr/bin

hope that’s useful.

As for the updates, yes, i didn’t get around to updating to 12.5.1 yet, i’m still on 12.4.

So that might sort out some of the issues perhaps…i avoided doing it as i had a load of open projects and research pages etc that i didn’t want to close/lose…

Here is the analgous way to compile a fortran program.

cat <<EOF >test.f90
write(*,*) 'Hello World!'
gfortran test.f90 && ./a.out

That should work the same as the previous C compiler test.

You will need to reboot after most security updates and certainly for OS updates. However, I think you can update the command line tools without a reboot. You might need to open new terminal windows afterwards to point to the new stuff, but the other things you have runnng, MS Word and Excel and Safari and stuff likek that, are all separate from the command line developer stuff. I typically run my laptop for a month or two at a time between reboots, and that includes giving Powerpoint presentations and switching networks several times a day while traveling.

Right, @RonShepard

First off not sure what a vi is in a terminal window…

However i managed to to the ‘code’ in a terminal window on the command line, and the results are fine, exactly like @awvwgk said for me to try in the Atom editor. The result is the same…(very interesting that one can actually write the c code on the command line and run it without and editor - i can see the reasons for having a editor of course, but it’s a very quick way to test some stuff out - cool)…and yet the cat test.c returns the code that was just input on the command line…also cool.

Yep all works a treat, the cc test as well, this is all very informative and useful info, thanks very much…

One thing i had to chuckle to myself though, was that, when i first got the ‘clang error’ message, i read it as clang, and in dropped a clanger, as in the sound a bell makes…(thought an Apple developer had a bit of a sense of humour) didn’t occur to me until this post that it might mean C- lang as in ‘the C language’…that’s how newbie i am! :smiley:

Ahh now this is interesting…i did the FORTRAN ‘code’ on the command line as you mentioned, and yet i get this wonderful clang error…

clang: error: invalid version number in ‘-macosx-version-min=12.0’

the same as i had before…so it seems to be that there’s something, not pointing to something that should be pointing too…

So i think it might be a case of an update and then reboot…

:frowning: Full update now done, I’m on 12.5.1 and i still get the clang error when trying to compile FORTRAN code…

It will be easier to respond if you tell us the command line(s) that caused the error messages to be issued, rather than just the error messages. Note that only a small subset of forum members are likely to use the same OS+software combination that you use, and the rest, being unable to reproduce your runs, have to go by what you report.

For the specific issue at hand, you may add the -v option to the compilation command, as in

gfortran -v test.f90

and you may see more output that may explain why clang is being used when you compile a Fortran source file.

@mecej4 ok valid point, but i think i wrote what i did at the top of the thread somewhere before, but for clarity, i just wrote exactly what the fortran-lang tutorial told me to type, which was, gfortran hello.f90 -o hello

now using your suggestion, i get something completely different, and here it is…

Driving: gfortran hello.f90 -v hello -mmacosx-version-min=12.0.0 -asm_macosx_version_min=12.0 -nodefaultexport -l gfortran -shared-libgcc

Using built-in specs.



Target: x86_64-apple-darwin21

Configured with: …/configure --prefix=/usr/local/opt/gcc --libdir=/usr/local/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-12 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-zstd=/usr/local/opt/zstd --with-pkgversion=‘Homebrew GCC 12.1.0’ --with-bugurl=Issues · Homebrew/homebrew-core · GitHub --with-system-zlib --build=x86_64-apple-darwin21 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk

Thread model: posix

Supported LTO compression algorithms: zlib zstd

gcc version 12.1.0 (Homebrew GCC 12.1.0)

COLLECT_GCC_OPTIONS=‘-v’ ‘-mmacosx-version-min=12.0.0’ ‘-asm_macosx_version_min=12.0’ ‘-nodefaultexport’ ‘-shared-libgcc’ ‘-mtune=core2’ ‘-dumpdir’ ‘a-’

/usr/local/Cellar/gcc/12.1.0/bin/…/libexec/gcc/x86_64-apple-darwin21/12/f951 hello.f90 -fPIC -quiet -dumpdir a- -dumpbase hello.f90 -dumpbase-ext .f90 -mmacosx-version-min=12.0.0 -mtune=core2 -version -fintrinsic-modules-path /usr/local/Cellar/gcc/12.1.0/bin/…/lib/gcc/current/gcc/x86_64-apple-darwin21/12/finclude -o /var/folders/pb/_jyh46v95dj6tpm5k5_p2gyh0000gn/T//cckWYt91.s

GNU Fortran (Homebrew GCC 12.1.0) version 12.1.0 (x86_64-apple-darwin21)

compiled by GNU C version 12.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

GNU Fortran2008 (Homebrew GCC 12.1.0) version 12.1.0 (x86_64-apple-darwin21)

compiled by GNU C version 12.1.0, GMP version 6.2.1, MPFR version 4.1.0, MPC version 1.2.1, isl version isl-0.25-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

COLLECT_GCC_OPTIONS=‘-v’ ‘-mmacosx-version-min=12.0.0’ ‘-nodefaultexport’ ‘-shared-libgcc’ ‘-mtune=core2’ ‘-dumpdir’ ‘a-’

as -arch x86_64 -v -mmacosx-version-min=12.0 -mllvm -x86-pad-for-align=false -force_cpusubtype_ALL -o /var/folders/pb/_jyh46v95dj6tpm5k5_p2gyh0000gn/T//ccFEMT5i.o /var/folders/pb/_jyh46v95dj6tpm5k5_p2gyh0000gn/T//cckWYt91.s

Apple clang version 11.0.3 (clang-1103.0.32.29)

Target: x86_64-apple-darwin21.6.0

Thread model: posix

InstalledDir: /Library/Developer/CommandLineTools/usr/bin

clang: error: invalid version number in ‘-mmacosx-version-min=12.0’

and to be clear as well, i’ve updated to Mac OSX 12.5.1 this morning.

Hope this output above means something to someone, as for me, it’s nothing more than blah blah…

Someone with an X64 Mac can correct me, but the detailed output generated by using the -v option (what you call “blah blah”) suggests that the problem is that you updated the OS to 12.5.1, but you did not do a matching update to the MAC development package (Xcode or a subset of it), which provides the assembler (command as ) as part of a set of development tools (compiler, assembler, linker, libraries, headers).

It seems to me that you have Clang tools with version 11.0.3, but the Gfortran compiler driver is calling them with the flag -mmacosx-version-min=12.0, which can cause them to cough up the “invalid version number…” message.

1 Like

Ok, that’s fine, and not a problem at all. So we’re a little bit closer to the problem of the clang error, thanks for that.

The question now is, how do i update the MAC development package? I had a previous discussion on here about installing Xcode, but that requires 12GB physically, but according to the download data and subsequent error message i need approx 40GB to download and install. I just don’t have the space to do that.

You need to update the XCode Command Line Tools (which strangely enough is separate from XCode itself). This StackOverflow question seems to suggest it is done this way:

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

It seems like every time I update my Mac, it breaks some linkages between Homebrew installed tools and Command Line Tools, and a complete removal and reinstall of Command Line Tools is necessary.

In my experience Macs “Just Work” so long as you’re not a software developer, and not trying to interact with anything that isn’t an Apple product. Otherwise it’s a frustrating battle with stuff like this.

1 Like

I think the idea to reinstall the command line tools is on the right track. I thought that Software Update would do that automatically, but if not, then a full reinstall should work.

When you do software development, the Mac mostly looks like any other unix/posix machine. You can shoot yourself in the foot just like if you are using linux or any other unix OS.

I do not think a full Xcode installl is necessary to solve this issue. That would include the full development environment for all of the suppored OS versions for all apple devices, macs, tablets, phones, TV, and watches. Yes, they give you the development environment for all of their watches! And they make it very easy to change targets with just a simple switch command. Oh, and also you can make fat binaries that will run natively on both intel an arm64 hardware. That is why it is 30 GB. But if you are just targeting your own mac, with just one OS version, then you don’t really need all of that.

There are also some commands like “brew doctor” and “brew upgrade” that could be tried. But I would recommend the command line tool reinstall first.

1 Like