I am trying to compile a software written in Fortran, which needs also some libraries written in C. The software was originally written to be compiled on x86 linux architecture, but I am trying to compile it on my Mac with Apple Silicon (M1 Max). I was able to modify both the script and the source code in order to remove the vast majority of errors and/or warnings, but I am now stuck with the linking of the libraries using ranlib and ar.
When compiling, the errors generated follow:
ar rv mapst.a \*.o
a - ispand.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: mapst.a(ispand.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
rm -f ispand.o
ranlib mapst.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive member: mapst.a(ispand.o) cputype (16777228) does not match previous archive members cputype (16777223) (all members must match)
As far as I understand, the issue arises with the flag of the compiler. Currently, the makefile has the following flags:
FTN = gfortran
FFLAGS = -O3 -Wuninitialized -fno-f2c -fno-automatic -fno-range-check -fno-backslash
CC = /usr/bin/gcc
CFLAGS = -c
Adding "-m64" to the gfortran (which, by the way, is the compiler provided with homebrew's gcc) flags, nothing changes, while adding "-arch arm" to the gcc flags, changes the architecture from 16777228 to 12, but in any case the error remains there.
Do you have any advice on how should I modify the Makefile in order to compile the software?
Solved! I found that the issue was related with the different compiler used for C and Fortran: while gcc comes from xcode, gfortran was installed using brew. As suspected, the issue was related with the libraries compiled for two slightly different architectures by default (arm64-apple-darwin23.1.0 for gcc and x86_64-apple-darwin22 for gfortran). I have added the -target x86_64-apple-darwin22
flag to gcc rules to solve the issue. Thank you to everyone!