Search code examples
netbeansfortrannetbeans-8automatic-differentiation

Change fortran compile order in NetBeans 8


I'm working in NetBeans 8 on CentOS 7 to change some old fortran code to replace numerical differentiation with automatic differentiation using OpenAD. OpenAD takes an annotated fortran function as input and generates an automatically differentiated function as output. That output function depends on some modules provided by OpenAD.

After adding the original files to the NetBeans project, generating the OpenAD output function, and adding that output and its dependencies to the project, the project will not build.

Fatal Error: Can't open module file 'oad_active.mod' for reading at (1): No such file or directory

OAD_active.f90 is one of the dependencies inserted and provided by OpenAD. If I compile that file first and then build the project (without cleaning), the build succeeds.

How do I tell NetBeans to compile OAD_active.f90 sooner in the build process?


Solution

  • NetBeans does not have a compile order, it creates Makefiles that express a dependency graph. The default graph is just the final executable depending on each of your sources.

    Additional dependencies for each source can be added through the context menu on each source in the Projects tab; choose "Properties", then in Categories choose "Fortran Compiler", and the Input section contains the Additional Dependencies field. The field is a space-delimited list. You probably want to change the configuration selector (at the top of the File Properties dialog) to "<All Configurations>". If the Projects tab is missing, it can be opened from the menubar item Window ▶︎ Projects.

    For the compiler to find a .mod file, the Additional Dependencies field must contain the corresponding .o file, not the source file. Entries in Additional Dependencies appear to be paths relative to the project root; the path to a .o file depends on which configuration is active (by default, one of "Debug" or "Release"). Makefile variables are allowed in the Additional Dependencies field, so you can use ${OBJECTDIR} for the configuration-dependent prefix, and the rest of the path matches the path to the source file.

    In my project, I have my sources in $project/src, and the OpenAD files in $project/src/OpenAD. There were three cases where I had to add Additional Dependencies:

    • Sources which call functions transformed by OpenAD: ${OBJECTDIR}/src/OpenAD/OAD_active.o
    • Sources generated by the OpenAD transformation: ${OBJECTDIR}/src/OpenAD/OAD_active.o ${OBJECTDIR}/src/OpenAD/w2f__types.o
    • $project/src/OpenAD/OAD_active.f90: ${OBJECTDIR}/src/OpenAD/w2f__types.o