2

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?

ShadSterling
  • 1,792
  • 1
  • 21
  • 40
  • Which build system does Netbeans use? Makefile or something custom? How does your current configuration look like? – Vladimir F Героям слава Jul 28 '15 at 19:51
  • I have no idea what build system it uses, but it does create a file named `Makefile`. I'm not sure what you want to know about my configuration, it's mostly the NetBeans default. – ShadSterling Jul 29 '15 at 03:48
  • Unfortunatly, I don't know Netbeans. If you used only the `Makefile`, I'd tell you to add a line `.o : OAD_active.o` somewhere inside it. But if Netbeans recreates the `Makefile` every time, this is too troublesome. Check the documentation for "Dependencies" – chw21 Jul 29 '15 at 06:33
  • NetBeans does recreate the `Makefile` (actually a set of files with inclusions) every time, but tracking that down set me on the right path to find the answer. Thanks! – ShadSterling Jul 29 '15 at 16:26

1 Answers1

3

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
ShadSterling
  • 1,792
  • 1
  • 21
  • 40
  • Bravo for both this question and this answer... I've just begun re-exploring Fortran... and am very interested in Fortran modules. I've had to Google to find this multiple times... I cannot find anywhere else (even Netbeans website) where this is explained. Thanks to @ShadSterling for creating a resource that I've re-discovered several times in the last several weeks. – TheGeeko61 Mar 23 '18 at 06:20