Failure with include files

I am trying to add the documentation and examples for the linked_list module (implemented during last year’s GSoC by @Chetan_Karwa) and I would like to use a small piece of code in most of these examples to print the lists. Since it is simply part of the examples and not of the module itself, I thought I could do this with a separate source file that contains a module with this auxiliary routine.

This fails for various reasons: the build process insists on find the source code somewhere other than in the example subdirectory. I have tried a bunch variations: including the source code of the module or merely include the source for the print routine, but in all these variations the included file cannot be found.

The only alternaitve I can think of is incorporating the source code in all examples, with the additional side effect that it will be repeated in the documentation 10 times in the documentation as well.

What is the way out of this? Surrending to the quirks of the build and just put the auxiliary routine into the linked_list module or is there a better solution?

It sounds like you are describing standard fortran but having a problem with the build. What commands are you using to build with? It sounds like you just need to configure where to look for source and mod files. Depending on what you are using to build with (fpm, CMake, make, shell calls to the compiler(s) and which compiler you are using it might just mean you need to add an option like -I, -J, --module, to a command or set a few environment or make variables. Seeing your file system structure (often the “tree” command) and your Makefile or whatever would help. If you copy all the source files into a scratch directory and call the compiler with the files in define-before-use order can you build your example program(s) ?

Oops, I should been clearer on that: I am preparing an addition to stdlib. My local ad hoc script works fine and everything gets built and works as expected, but when I put the code in my clone of the stdlib repository, I get error messages about the automatic build. So this is all part of the actions taken in stdlib.

1 Like

I looked your PR.
In fpm you need to tell the fpm.toml where your include file will be, otherwise it will try to compile it or simply won’t find it.

I have this project where I had to:

[ library ]
include-dir = "include"

And then every file I use the include keyword is in a folder include/.
I guess this is why the CI is failing.

EDIT: I forgot to mention that I faced this issue before

Well, that is a thought :slight_smile:. I checked the other example directories and only see CMakeLists.txt files. But it is clear that the build process needs some help and with this (fpm.toml or a CMake text file) I can provide that help. Thanks.

Well, I studied the documentation and put together a CMakeLists.txt file. Some iterations were required to get to the point where it was apparently accepted, but I still cannot get the examples to build, sigh. It looks very much like the build system is ignoring these include directories. This is for instance the sort of errors I see:

 + gfortran -c example/example_linked_absorb.f90  -Wall -Wextra -Wimplicit-interface -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -J build/gfortran_2A42023B310FA28D/stdlib -I build/gfortran_2A42023B310FA28D/stdlib  -o build/gfortran_2A42023B310FA28D/stdlib/example_example_linked_absorb.f90.o
example/example_linked_absorb.f90:44: Error: Can't open included file 'linked_list_aux.f90'
<ERROR> Compilation failed for object " example_example_linked_absorb.f90.o "
<ERROR>stopping due to failed compilation
STOP 1
Error: Process completed with exit code 1.

There is no indlcation of an include directory, whereas the macro I currently use is an extension of the ADD_EXAMPLE macro:

macro(ADD_EXAMPLE_INCLUDE name)
    add_executable(example_${name} example_${name}.f90)
    target_include_drectories(example_${name} ${CMAKE_CURRENT_SOURCE_DIR})
    target_link_libraries(example_${name} "${PROJECT_NAME}")
    add_test(NAME ${name}
             COMMAND $<TARGET_FILE:example_${name}> ${CMAKE_CURRENT_BINARY_DIR}
             WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endmacro(ADD_EXAMPLE_INCLUDE)

If anybody can help me get this right, that would be great.

@Arjen I commented and proposed some solutions directly in your PR on Github.

@jeremie.vandenplas, thanks! I will have a look. That will probably not be for the next few days, but I do appreciate this.

Well, it took some iterations, but the result is encouraging:

  • I have a better understanding of the two build systems (CMake and CI/fpm)
  • The examples and the test program are built correctly and run correctly

However, I now face a problem with the build of the API docs. The message is:

...
Preprocessing /Users/runner/work/stdlib/stdlib/src/stdlib_linalg_outer_product.fypp
Reading file src/f18estop.f90
Reading file src/stdlib_sorting_sort_index.fypp
Preprocessing /Users/runner/work/stdlib/stdlib/src/stdlib_sorting_sort_index.fypp

Processing documentation comments...
Correlating information from different parts of your project...
    project.correlate()
  File "/usr/local/Cellar/ford/6.1.15/libexec/lib/python3.10/site-packages/ford/fortran_project.py", line 254, in correlate
    container.correlate(self)
  File "/usr/local/Cellar/ford/6.1.15/libexec/lib/python3.10/site-packages/ford/sourceform.py", line 1078, in correlate
    if proc.module and proc.name.lower() in self.all_procs:
AttributeError: 'FortranSubmoduleProcedure' object has no attribute 'module'
Error: Process completed with exit code 1.

As you can see there is no indication in what file things are going wrong. None of the source files I have added has a “submodule” statement, which I guess is where the Ford processor is failing.

Does anybody know how to analyse this problem?

I tried to build the documentation locally, using FORD version 6.0.0 (on Windows, Anaconda3 environment, should prove to be important) and succeeded after cleaning up some UTF-encoded characters in the comments. So, no complaints about a FortranSubmoduleProcedure object!