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.
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.
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.
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.
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?
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?
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)…
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?