#Compiling MODLFOW files with Pymake **HOW TO FIND REQUIRED COMPILER FLAGS FOR COMPILING WITH gfortran 11.2 ON MACOS MONTEREY ?** @ Theo Olsthoorn, 2021-11-01 Compilation and linking troubles on Big Sur because Apple changed things for compilers: no stdlib.h and stdio.h in /usr/include no direct access to dynamic libraries. It must now go through the dynamic library cache. Therefore Pymake is no longer up-to-date and we have to alter the makefile that it generates to get the compiling and linking done. **INCLUDE DIRECTORY** First make sure that the include files are found by copiing them to the standard directory where they are searched The coarse method is (which I did): sudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include/*.h /usr/local/include However, this may be a better (more hygienic way) to achieve the same effect export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ or better, and simpler in the end, put an INCLUDEDIR directive in the make file and then use flag -I$(INCLUDEDIR) with the CFLAGS INCLUDEDIR = /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ **Apples new "dynamic link chache** To use the dynamic link cache see below, where we let gcc tell what the location is of the cache (namely:) -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk This information was found in the link: https://developer.apple.com/forums/thread/669094 Here is a terminal session that shows how to get the information on the "dynamic link cache" (i.e. the sysroot): The dynamic library cache is shipped by Apple since MacOS Catalina. “Most folks compile C programs using the compiler driver. For example:” % sw_vers ProductName: macOS ProductVersion: 11.0.1 BuildVersion: 20B29 % xcode-select -p /Applications/Xcode.app/Contents/Developer % cat test.c #include const unsigned char pmessagebuf[13] = "hello world\n"; int main (int argc, char* argv[]) { write(STDOUT_FILENO, (void*)pmessagebuf, 12); return(0); } % cc test.c -o test % ./test hello world “If you want to compile each file separately, you can use the compiler driver for that too:” % rm test % cc -c test.c % cc test.o -o test % ./test hello world “If you want to explicitly run the linker, you’ll need to tell it what SDK to use. A good way to work out the exact syntax is to run the compiler driver with -v:” % cc test.o -v -o test Apple clang version 12.0.0 (clang-1200.0.32.27) Target: x86_64-apple-darwin20.1.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 11.0.0 11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o test -L/usr/local/lib test.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a “The ‘secret sauce’ here is -syslibroot.” (But in gfortran this option is -—sysroot) The final solution is as follows: Define in the makefile a variable SYSROOT = ….(copy the argument from above, as one of the options shown by cc test.o -v -o test) And then put the option in the line that tells how to construct the program in the makefile (the optioni recognized by gcc is —sysroot, so use that): like so in the makefile SYSLIBROOT = /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk # Define the objects that make up mf2005 mf2005: $(OBJECTS) -$(F90) $(F90FLAGS) -o $(PROGRAM) --sysroot $(SYSLIBROOT) $(OBJECTS) $(SYSLIBS) -I$(OBJDIR) -J$(OBJDIR)