# Debug symbols in Fortran with Ninja and Intel compiler on Windows

**URL:** https://discourse.cmake.org/t/debug-symbols-in-fortran-with-ninja-and-intel-compiler-on-windows/2762
**Category:** Development
**Tags:** os:windows, gen:ninja, comp:intel, lang:fortran
**Created:** [February 15, 2021, 10:14am UTC](https://discourse.cmake.org/t/debug-symbols-in-fortran-with-ninja-and-intel-compiler-on-windows/2762 "2021-02-15T10:14:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ascmagma](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@ascmagma](https://discourse.cmake.org/u/ascmagma)
#### Post date: [February 15, 2021, 10:14am UTC](https://discourse.cmake.org/t/debug-symbols-in-fortran-with-ninja-and-intel-compiler-on-windows/2762/1 "2021-02-15T10:14:23Z")

</div>

Hi guys,

we have a problem with debugging Fortran code, because the source code reference in the object file is not set correctly. Find below a minimal example to reproduce the problem.

Apparently, during preprocessing of a source file with the Intel compiler the result is written to the terminal and then redirected into a subfolder. This behavior is defined in CMAKE\_Fortran\_PREPROCESS\_SOURCE (more precisely, here: -E \> \<PREPROCESSED\_SOURCE\>). The preprocessed file contains a reference to the source file in the first line comment (# 1 “…\main.f” in the minimal example), which is used by the Intel compiler to create the reference in the object file. But since the preprocessed file is shifted into a subfolder, the relative path becomes outdated and in the object file we get an invalid path (CMakeFiles\hello\_world\_fortran.dir…\main.f in the minimal example).

We use Ninja version 1.9.0, CMake version 3.19.3, IFort version 19.1.1.216, and Fortran 77.

Any help to fix the problem and suggestions, how to circumvent it for the moment is appreciated. If you need additional information, I will be happy to provide.

Thanks in advance  
Andreas

* * *

Since I cannot upload attachments here is the minimal example in text form:  
**main.f**  
PROGRAM HELLO  
C  
C The typical hello world program  
C  
WRITE (_,_) ‘Hello World!’  
END

**CMakeLists.txt**  
set ( CMAKE\_MAKE\_PROGRAM “N:/software/ninja-build/ninja/v1.9.0/WINDOWS64/ninja.exe” )  
set ( CMAKE\_Fortran\_COMPILER “C:/Program\ Files\ (x86)/IntelSWTools/compilers\_and\_libraries\_2020.1.216/windows/bin/intel64/ifort.exe” )  
set ( CMAKE\_Fortran\_COMPILER\_FORCED TRUE )

cmake\_minimum\_required(VERSION 3.19)  
project(hello\_world\_fortran Fortran)

message( “CMAKE\_Fortran\_PREPROCESS\_SOURCE ${CMAKE\_Fortran\_PREPROCESS\_SOURCE}” )

add\_executable(hello\_world\_fortran main.f)

**README.txt**

- **CMAKE NINJA IFORT DEBUG SYMBOL REPRODUCER**

- Copy reproducer files from above

- Adapt the Fortran file to fixed format (the white spaces do not show here in the forum), so add 6 white spaces at the beginning of each non-comment line.

- Adapt the path to the Fortran Compiler and to Ninja in CMakeLists.txt

- Start command prompt

- Setup compiler environment  
“C:\Program Files (x86)\IntelSWTools\compilers\_and\_libraries\_2020.1.216\windows\bin\compilervars.bat” vs2019 intel64

- Change into reproducer folder

- Create build directory  
mkdir build  
cd build

- Run CMake  
cmake -DCMAKE\_BUILD\_TYPE=Debug -G Ninja …

- Build  
ninja -v all

- **THE PROBLEM**

- Open CMakeFiles\hello\_world\_fortran.dir\main.f.obj in a text editor. Here, you see the source path ‘CMakeFiles\hello\_world\_fortran.dir…\main.f’.

- This path is wrong and therefore debug source information in Fortran code is not accessible.

- **FURTHER INFORMATION**

- Open CMakeFiles\hello\_world\_fortran.dir\main.f-pp.f.

- In the first line is a relative path to the source, which is used by IFort to produce the wrong path in the object file.

- Looking at the preprocessing step or rather the corresponding CMake variable: CMAKE\_Fortran\_PREPROCESS\_SOURCE \<CMAKE\_Fortran\_COMPILER\> -fpp -E \> \<PREPROCESSED\_SOURCE\>

- With -E you get terminal output of the preprocessed file. This output then is directed into PREPROCESSED\_SOURCE in a subfolder, which breaks the relative path.

- We use Ninja version 1.9.0, CMake version 3.19.3, and IFort version 19.1.1.216.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 15, 2021, 3:02pm UTC](https://discourse.cmake.org/t/debug-symbols-in-fortran-with-ninja-and-intel-compiler-on-windows/2762/2 "2021-02-15T15:02:11Z")

</div>

Thanks for the report. There is now support for skipping the preprocessing step if that is suitable for you. It was added in CMake 3.18 and you can set it at [the target level](https://cmake.org/cmake/help/latest/prop_tgt/Fortran_PREPROCESS.html) or [per-source file](https://cmake.org/cmake/help/latest/prop_sf/Fortran_PREPROCESS.html) if one is more appropriate.

In the meantime, this should probably be addressed since there are files which do require preprocessing. Could you please file [an issue](https://gitlab.kitware.com/cmake/cmake/-/issues) for this?

Cc: @brad.king

---

<div class="post-metadata">

### Author: ![ascmagma](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/e47c2d/32.png) [@ascmagma](https://discourse.cmake.org/u/ascmagma)
#### Post date: [February 15, 2021, 3:51pm UTC](https://discourse.cmake.org/t/debug-symbols-in-fortran-with-ninja-and-intel-compiler-on-windows/2762/3 "2021-02-15T15:51:16Z")

</div>

Added the [issue](https://gitlab.kitware.com/cmake/cmake/-/issues/21816).
