Incompatible gfortran version

Dear fluka experts:

I am updating the fluka to 4.2.1, and run it on flair. An error occurs:
With Mac, Catalina, 10.15.6

Dir:   /Users/Danny/Documents/Fluka/fluka4-2.1
Data:  /Users/Danny/Documents/Fluka/fluka4-2.1/data
/Users/Danny/Documents/Fluka/fluka4-2.1/bin/rfluka: line 108: gfortran: command not found
/Users/Danny/Documents/Fluka/fluka4-2.1/bin/rfluka: line 112: [: -eq: unary operator expected
/Users/Danny/Documents/Fluka/fluka4-2.1/bin/rfluka: line 112: [: -ge: unary operator expected
Error: Incompatible gfortran version!
   System gfortran version: 
   FLUKA package version:   8

Here are my following operations:

  1. checked the gcc -v, prompt shows :9.3;
  2. brew install gcc-8.5;
  3. recheck the gcc-v, prompt shows :8.5
  4. removed the fluka-4.2.1, and reinstall;
  5. cd /flukapath/src, type '“make”

Then another error occurs:

In file included from usbmax.c:28:
/opt/local/lib/gcc9/gcc/x86_64-apple-darwin16/9.3.0/include-fixed/math.h:45:10: fatal error: sys/cdefs.h: No such file or directory
   45 | #include <sys/cdefs.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
make[1]: *** [usbmax.o] Error 1
make: *** [tools] Error 2

I found gfortran version is still gcc9.3

Now the situation is:
gcc -v returns gcc version 8.5.0 (Homebrew GCC 8.5.0)
gfortran -v returns gcc version 9.3.0 (MacPorts gcc9 9.3.0_0)

Do not know how to fix this.

Dear @songhg19

HomeBrew and Macports cannot coexist well on the same machine.
The simplest solution to install FLUKA (and Flair) is to remove HomeBrew from your machine.
If you need HomeBrew for any other scope, please let me know and we can find a hack, which - I stress - is not the recommended approach.

Cheers Luigi

Dear @luillo

Thanks for your reply.
I can remove HomeBrew, without any attachments.
So how should I solve this problem?
How to change the gfortran version?

  1. Just now I removed the Homebrew.
    gcc -v and gfortran -v are now consistent, "gcc version 9.3.0 (MacPorts gcc9 9.3.0_0) "

  2. Re-install MacPorts

  3. Install gcc8 by the following commands:

sudo port install gcc8
  1. Change the default gcc version by the following, I got gcc version 8.5.0 (MacPorts gcc8 8.5.0_1)
sudo port select --set gcc mp-gcc8
  1. Type “make” in the /pathtofluka/src directory, an error occurs:
gfortran -o /Users/Danny/Documents/Fluka/fluka4-2.1//bin/fluka -fuse-ld=bfd -L/Users/Danny/Documents/Fluka/fluka4-2.1//lib -lfluka
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
make: *** [/Users/Danny/Documents/Fluka/fluka4-2.1//bin/fluka] Error 1

I see another post in this forum, and I did the same procudeures:

gfortran -print-sysroot

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk

 port echo installed

I uploaded the output in the attachment.

Thanks for you reply.
prompt.txt (7.7 KB)

Dear @songhg19

it’s not clear to me why you performed steps 2-5…

Nevertheless, from the file you attached, now you have gcc8 and gcc9 on your machine, so the default gcc version should point to one of these two with the command

sudo port select --set gcc mp-gcc8
or (exclusively!)
sudo port select --set gcc mp-gcc9

After that, let me know what is the message when you compile FLUKA.

Cheers Luigi

Dear @luillo

MacPorts seems to obsolete, so step2-3 are performed.
I set the gfortran version to 8.5 (GNU Fortran (MacPorts gcc8 8.5.0_1) 8.5.0), using

sudo port select --set gcc mp-gcc8

I recompiled the fluka, error shows as follow:

gfortran -o /Users/Danny/Documents/Fluka/fluka4-2.1//bin/fluka -fuse-ld=bfd -L/Users/Danny/Documents/Fluka/fluka4-2.1//lib -lfluka
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
make: *** [/Users/Danny/Documents/Fluka/fluka4-2.1//bin/fluka] Error 1

Hello @songhg19 ,

can you check if the directory that is printed by this command exists?
gcc -print-sysroot

And what is the output of command port diagnose ?

Cheers Luigi

Dear @luillo

The result for “gcc -print-sysroot” is

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk

And the result for “port diagnose” is:

Warning: found dylibs in your /usr/local/lib directory. These are known to cause problems. We'd recommend you remove them.
Warning: it seems you have Homebrew installed on this system -- Because Homebrew uses /usr/local, this can potentially cause issues with MacPorts. We'd recommend you either uninstall it, or move it from /usr/local for now.

Does this folder exist?
I guess no. If I’m correct, what is the output of the command?

ls -l /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

It looks like that HomeBrew is still present on your machine.
Have you followed the instructions here?

Cheers Luigi

Dear @luillo

You’re right, the folder doesn’t exists.

The result for the command:

ls -l /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/

is:

drwxr-xr-x  5 root  wheel  160 11 30  2020 DriverKit20.2.sdk
drwxr-xr-x  7 root  wheel  224 11 30  2020 MacOSX.sdk
lrwxr-xr-x  1 root  wheel   10  3 21  2021 MacOSX11.1.sdk -> MacOSX.sdk

I followed exactly the script to uninstall the homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

I remembered that there are tips, warning that some of the folding might be deleted mannually. However, I didn’t delete these folders.

Now I try to rerun the uninstall script, the terminal prompt:

/bin/bash: line 235: brew: command not found
Failed to locate Homebrew!

Dear @songhg19,

you upgraded to a newer version of Xcode, but MacPorts was installed with an older version.

The simplest (and dirtier) solution is to create a symbolic link:
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
sudo ln -s MacOSX.sdk MacOSX10.15.sdk

then you should be able to compile FLUKA.

The appropriate solution (and more time consuming) is to reinstall MacPorts as well.
You can follow the instructions here

Let us know if this solves your installation problem.

Cheers Luigi

Dear @luillo

Thanks! It works with your “symbolic link” suggestion.
I have reinstalled the MacPorts before the comping using the same webpage actually.

Now the problem is when I ran the fluka in Flair, it still can not run properly, showing:

Dir: /Users/Danny/Desktop/simulation
Cmd: /usr/bin/nohup /Users/Danny/Documents/Fluka/fluka4-2.1/bin/rfluka -M 5 fssV3

                                  F L U K A

Dir:   /Users/Danny/Documents/Fluka/fluka4-2.1
Data:  /Users/Danny/Documents/Fluka/fluka4-2.1/data
/Users/Danny/Documents/Fluka/fluka4-2.1/bin/rfluka: line 108: gfortran: command not found
/Users/Danny/Documents/Fluka/fluka4-2.1/bin/rfluka: line 112: [: -eq: unary operator expected
/Users/Danny/Documents/Fluka/fluka4-2.1/bin/rfluka: line 112: [: -ge: unary operator expected
Error: Incompatible gfortran version!
  System gfortran version: 
  FLUKA package version:   8

When running the input file in a terminal, it works fine.
Don’t know how the solve this.
Here is the peference setting in the configuration of Flair.

Dear @songhg19 ,

looks like that you are running Flair from an old terminal.
Can you try from a new terminal?

Dear @luillo
You mean installing a new version of Flair?
I am now using the Flair-3.0.9.

Dear @songhg19 ,

No, there is no need to install a newer version of Flair (nevertheless, it would be a good idea since your version is about TWO year old…)

The message says that gfortran is not found, but it IS available in your machine since you compiled FLUKA. So the problem is that the Terminal from which you are running Flair does not have all the environment variables set up.

If you open a new terminal, this should normally fix the problem.
Screenshot 2022-03-15 at 10.24.11

Otherwise, can you provide the output of these commands?
which gfortran
gfortran --version

Cheers Luigi

Dear @luillo
Thanks for your reply. The problem is sovled!
I’ve just reinstalled the flair-3.1 & geoviewer, it is now working fine.

The output for commands :

which gfortran
 /opt/local/bin/gfortran

The output for commands :

gfortran --version
GNU Fortran (MacPorts gcc8 8.5.0_1) 8.5.0