Compilation issue with ninja build system

I am getting a compilation error when trying to build with the ninja build system (I can’t link as a new user, but if you google ‘ninja build’ it’s the first result). I have the latest commit of garfield++ and when I follow the build instructions from the README but use ninja, i.e.

mkdir build && cd build
cmake -GNinja ../

I get the following errors

$ ninja
[1/246 45.5/s (3) 0.022] Building Fortran preprocessed Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f
FAILED: Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi 
/usr/bin/gfortran -cpp -Dmagboltz_EXPORTS  -O3 -DNDEBUG -O3 -JMagboltz -fPIC -std=legacy -E /home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f -o Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f && /usr/bin/cmake -E cmake_ninja_depends --tdi=Magboltz/CMakeFiles/magboltz.dir/FortranDependInfo.json --lang=Fortran --pp=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f --dep=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f.d --obj=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o --ddi=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi
/home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f:6948:0:

 6948 |      /**2)*WSSST(JPRINT)/(JPRINT*2.0D0*ZSTEP)
      | 
Error: unterminated comment
[2/246 80.0/s (2) 0.025] Building Fortran preprocessed Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f
FAILED: Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f Degrade/CMakeFiles/degrade.dir/degrad.f.o.ddi 
/usr/bin/gfortran -cpp -Ddegrade_EXPORTS  -O3 -DNDEBUG -O3 -JDegrade -fPIC -std=legacy -E /home/ijc/software/garfield/garfieldpp/Degrade/degrad.f -o Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f && /usr/bin/cmake -E cmake_ninja_depends --tdi=Degrade/CMakeFiles/degrade.dir/FortranDependInfo.json --lang=Fortran --pp=Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f --dep=Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f.d --obj=Degrade/CMakeFiles/degrade.dir/degrad.f.o --ddi=Degrade/CMakeFiles/degrade.dir/degrad.f.o.ddi
/home/ijc/software/garfield/garfieldpp/Degrade/degrad.f:22550:0:

22550 |      /*DLOG((tri_2**2+C1-DSQRT(tri_2**2+C1)*(tri_1+tri_2)+tri_1*tri_2)/
      | 
Error: unterminated comment
[3/246 2.3/s (1) 1.308] Generating GarfieldDict.cxx, libGarfieldDict_rdict.pcm, libGarfieldDict.rootmap
Warning in cling::IncrementalParser::CheckABICompatibility():
  Possible C++ standard library mismatch, compiled with __GLIBCXX__ '20230511'
  Extraction of runtime standard library version was: '20230614'
ninja: build stopped: subcommand failed.

If I don’t use ninja, and use the default make, the project compiles without issue even when I use parallel builds.

Not sure if this is a bug in garfield++ or ninja?

I’m on a fully up to date fedora38 and other software versions are

$ cmake --version
cmake version 3.26.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
$ ninja --version
1.11.1
$ gfortran --version
GNU Fortran (GCC) 13.1.1 20230614 (Red Hat 13.1.1-4)
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Hello @php1ic,

welcome to the forum! Maybe @hschindl could have a look from Garfield++ perspective.

Cheers,
Marta

The two “unterminated comment” errors should be quite easy to fix. I’ll take a look…

I’ve just pushed a commit that I hope fixes this issue:

Can you give it a try?

Same error but on different lines

$ ninja
[1/246 23.8/s (3) 0.042] Building Fortran preprocessed Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f
FAILED: Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi 
/usr/bin/gfortran -cpp -Dmagboltz_EXPORTS  -O3 -DNDEBUG -O3 -JMagboltz -fPIC -std=legacy -E /home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f -o Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f && /usr/bin/cmake -E cmake_ninja_depends --tdi=Magboltz/CMakeFiles/magboltz.dir/FortranDependInfo.json --lang=Fortran --pp=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f --dep=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f.d --obj=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o --ddi=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi
/home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f:19117:0:

19117 |      /*EIN(12)))-BETA2-DEN(I)/2.0)*BBCONST*EN/(EN+EIN(12)+E(3))*1.0107
      | 
Error: unterminated comment
[2/246 42.6/s (2) 0.047] Building Fortran preprocessed Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f
FAILED: Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f Degrade/CMakeFiles/degrade.dir/degrad.f.o.ddi 
/usr/bin/gfortran -cpp -Ddegrade_EXPORTS  -O3 -DNDEBUG -O3 -JDegrade -fPIC -std=legacy -E /home/ijc/software/garfield/garfieldpp/Degrade/degrad.f -o Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f && /usr/bin/cmake -E cmake_ninja_depends --tdi=Degrade/CMakeFiles/degrade.dir/FortranDependInfo.json --lang=Fortran --pp=Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f --dep=Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f.d --obj=Degrade/CMakeFiles/degrade.dir/degrad.f.o --ddi=Degrade/CMakeFiles/degrade.dir/degrad.f.o.ddi
/home/ijc/software/garfield/garfieldpp/Degrade/degrad.f:31979:0:

31979 |      /*AFAN1EXC)/ANF
      | 
Error: unterminated comment
[3/246 1.7/s (1) 1.754] Generating GarfieldDict.cxx, libGarfieldDict_rdict.pcm, libGarfieldDict.rootmap
Warning in cling::IncrementalParser::CheckABICompatibility():
  Possible C++ standard library mismatch, compiled with __GLIBCXX__ '20230511'
  Extraction of runtime standard library version was: '20230614'
ninja: build stopped: subcommand failed.

I don’t know fortran, so can’t comment if this is an actual bug, but as mentioned, if I don’t use ninja and stick to make, there are no compilation issues.

Have tried a bit of debugging, but quickly got out of my depth.

If I try and compile the magboltz.f file without using any build system it builds

$ gfortran --std=legacy -o Magboltz/magboltz.o -c Magboltz/magboltz.f 
$ ls Magboltz/
CMakeLists.txt  magboltz.f  magboltz.o

Does this suggest something is wrong with the build command that ninja constructs? Below is the verbose output from make and ninja, restricted to single thread mode.

Make does this (and works)

[  1%] Building Fortran object Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o
cd /home/ijc/software/garfield/make_build/Magboltz && /usr/bin/gfortran -Dmagboltz_EXPORTS  -O3 -DNDEBUG -O3 -fPIC -std=legacy -c /home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f -o CMakeFiles/magboltz
.dir/magboltz.f.o
[  2%] Linking Fortran shared library libmagboltz.so
cd /home/ijc/software/garfield/make_build/Magboltz && /usr/bin/cmake -E cmake_link_script CMakeFiles/magboltz.dir/link.txt --verbose=1
/usr/bin/gfortran -fPIC -O3 -DNDEBUG -O3 -shared -Wl,-soname,libmagboltz.so.11 -o libmagboltz.so.11 CMakeFiles/magboltz.dir/magboltz.f.o 
cd /home/ijc/software/garfield/make_build/Magboltz && /usr/bin/cmake -E cmake_symlink_library libmagboltz.so.11 libmagboltz.so.11 libmagboltz.so

Ninja does this (and doesn’t work)

[140/246 67.1/s (1) 2.087] /usr/bin/gfortran -cpp -Dmagboltz_EXPORTS  -O3 -DNDEBUG -O3 -JMagboltz -fPIC -std=legacy -E /home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f -o Magboltz/CMakeFiles/magboltz.d
ir/magboltz.f-pp.f && /usr/bin/cmake -E cmake_ninja_depends --tdi=Magboltz/CMakeFiles/magboltz.dir/FortranDependInfo.json --lang=Fortran --pp=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f --dep=Magboltz/CMake
Files/magboltz.dir/magboltz.f-pp.f.d --obj=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o --ddi=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi
FAILED: Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi 
/usr/bin/gfortran -cpp -Dmagboltz_EXPORTS  -O3 -DNDEBUG -O3 -JMagboltz -fPIC -std=legacy -E /home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f -o Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f && /usr/
bin/cmake -E cmake_ninja_depends --tdi=Magboltz/CMakeFiles/magboltz.dir/FortranDependInfo.json --lang=Fortran --pp=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f --dep=Magboltz/CMakeFiles/magboltz.dir/magboltz
.f-pp.f.d --obj=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o --ddi=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi
/home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f:19117:0:

19117 |      /*EIN(12)))-BETA2-DEN(I)/2.0)*BBCONST*EN/(EN+EIN(12)+E(3))*1.0107
      | 
Error: unterminated comment

Also notice that building the fortran files is the very first things make does. Ninja attempts to build them in the middle of other files. Not sure if this has any effect?

1 Like

It seems to come from the preprocessing step. Can you try adding the flag -nocpp to the compile options in the CMakeLists.txt of the Magboltz and Degrade folders?

No luck

diff --git a/Degrade/CMakeLists.txt b/Degrade/CMakeLists.txt
index e633edce..fe51eff5 100644
--- a/Degrade/CMakeLists.txt
+++ b/Degrade/CMakeLists.txt
@@ -7,7 +7,7 @@ message(STATUS "Creating a new library named ${libname} with API version ${lib_a
 add_library(${libname} SHARED "")
 add_library(Garfield::${libname} ALIAS ${libname})
 target_sources(${libname} PRIVATE degrad.f)
-target_compile_options(${libname} PRIVATE -std=legacy)
+target_compile_options(${libname} PRIVATE -std=legacy -nocpp)
 # Sets the API version of the library
 set_property(TARGET ${libname} PROPERTY SOVERSION ${lib_apiver})
 
diff --git a/Magboltz/CMakeLists.txt b/Magboltz/CMakeLists.txt
index 0969f387..4de2d721 100644
--- a/Magboltz/CMakeLists.txt
+++ b/Magboltz/CMakeLists.txt
@@ -7,7 +7,7 @@ message(STATUS "Creating a new library named ${libname} with API version ${lib_a
 add_library(${libname} SHARED "")
 add_library(Garfield::${libname} ALIAS ${libname})
 target_sources(${libname} PRIVATE magboltz.f)
-target_compile_options(${libname} PRIVATE -std=legacy)
+target_compile_options(${libname} PRIVATE -std=legacy -nocpp)
 # Sets the API version of the library
 set_property(TARGET ${libname} PROPERTY SOVERSION ${lib_apiver})

Looks like ninja creates a gfortran command using an option that necessitates to use of -cpp

$ ninja
[1/246 125.0/s (3) 0.008] Building Fortran preprocessed Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f
FAILED: Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi 
/usr/bin/gfortran -cpp -Dmagboltz_EXPORTS  -O3 -DNDEBUG -O3 -JMagboltz -fPIC -std=legacy -nocpp -E /home/ijc/software/garfield/garfieldpp/Magboltz/magboltz.f -o Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f && /usr/bin/cmake -E cmake_ninja_depends --tdi=Magboltz/CMakeFiles/magboltz.dir/FortranDependInfo.json --lang=Fortran --pp=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f --dep=Magboltz/CMakeFiles/magboltz.dir/magboltz.f-pp.f.d --obj=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o --ddi=Magboltz/CMakeFiles/magboltz.dir/magboltz.f.o.ddi
gfortran: error: gfortran does not support -E without -cpp
[2/246 222.2/s (2) 0.009] Building Fortran preprocessed Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f
FAILED: Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f Degrade/CMakeFiles/degrade.dir/degrad.f.o.ddi 
/usr/bin/gfortran -cpp -Ddegrade_EXPORTS  -O3 -DNDEBUG -O3 -JDegrade -fPIC -std=legacy -nocpp -E /home/ijc/software/garfield/garfieldpp/Degrade/degrad.f -o Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f && /usr/bin/cmake -E cmake_ninja_depends --tdi=Degrade/CMakeFiles/degrade.dir/FortranDependInfo.json --lang=Fortran --pp=Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f --dep=Degrade/CMakeFiles/degrade.dir/degrad.f-pp.f.d --obj=Degrade/CMakeFiles/degrade.dir/degrad.f.o --ddi=Degrade/CMakeFiles/degrade.dir/degrad.f.o.ddi
gfortran: error: gfortran does not support -E without -cpp
[3/246 2.3/s (1) 1.287] Generating GarfieldDict.cxx, libGarfieldDict_rdict.pcm, libGarfieldDict.rootmap
Warning in cling::IncrementalParser::CheckABICompatibility():
  Possible C++ standard library mismatch, compiled with __GLIBCXX__ '20230511'
  Extraction of runtime standard library version was: '20230614'
ninja: build stopped: subcommand failed.

Hm, then I’m afraid I’m not sure what to do. Maybe one of the ROOT experts could help?

In theory, one could also “fix” all the “offending” lines (the ones that start with a /* but that might be a lot of work (not sure how many lines like that there are in the Magboltz and Degrade source files)…

That, however, may be automatized with find and sed (hopefully). To be honest, I don’t know Fortran, so what should be the replacement it that case?

Can we push this upstream to the file maintainers? Can it be classed as a bug?

I don’t know how you update each file when a new version is released, but altering the file does not feel like the correct way to go.

The pattern is in each file quite a few times so definitely a job for automation if we go that way

$ grep -cE "[[:space:]]/\*" Magboltz/magboltz.f 
340
$ grep -cE "[[:space:]]/\*" Degrade/degrad.f 
352

I also don’t know Fortran, but from the previous commits, it looks like the asterisks (*) needs to be moved up to the end of the previous line.

$ grep -E -nm1 -B1 "[[:space:]]/\*" Degrade/degrad.f
31978-      AFAN3EXC=(ANCL3EXC-3.0D0*AFAN1EXC*ANCL2EXC+2.0D0*ANCL1EXC*AFAN1EXC
31979:     /*AFAN1EXC)/ANF

becomes

31978:      AFAN3EXC=(ANCL3EXC-3.0D0*AFAN1EXC*ANCL2EXC+2.0D0*ANCL1EXC*AFAN1EXC*
31979:     /AFAN1EXC)/ANF

Sorry for the late reply. I think the easiest solution might be to replace the / in column 6 of the offending lines by another character (I think it can be pretty much anything character, but let’s maybe use an ampersand &). Can you give it a try?

That looks to do it :+1:

I used this command to do the find and replace on both files

sed -i 's|\([[:space:]]\)\(/\)\(\*\)|\1\&\3|' Degrade/degrad.f

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.