Problem 2298 - Version 10.7: G4Profiler.icc: PTL/Globals.hh: No such file or directory
Summary: Version 10.7: G4Profiler.icc: PTL/Globals.hh: No such file or directory
Status: CLOSED FIXED
Alias: None
Product: Geant4
Classification: Unclassified
Component: cmake (show other problems)
Version: other
Hardware: All Linux
: P4 normal
Assignee: Ben Morgan
URL:
Depends on:
Blocks:
 
Reported: 2020-12-07 14:59 CET by Peter Jansson
Modified: 2020-12-17 17:52 CET (History)
0 users

See Also:


Attachments
Patch to resolve PTL include path errors outside of CMake (5.80 KB, text/plain)
2020-12-17 17:51 CET, Ben Morgan
Details

Note You need to log in before you can comment on or make changes to this problem.
Description Peter Jansson 2020-12-07 14:59:02 CET
In version 10.7, I get a fatal error during compilation:

"
In file included from /usr/local/geant4.10.07/include/Geant4/G4Profiler.hh:43,
                 from /usr/local/geant4.10.07/include/Geant4/G4Step.hh:56,
                 from /usr/local/geant4.10.07/include/Geant4/G4VSensitiveDetector.hh:33,
                 from /usr/local/geant4.10.07/include/Geant4/G4MultiFunctionalDetector.hh:32,
                 from /usr/local/geant4.10.07/include/Geant4/G4VPrimitiveScorer.hh:37,
                 from /.../:
/usr/local/geant4.10.07/include/Geant4/G4Profiler.icc:44:12: fatal error: PTL/Globals.hh: No such file or directory
   44 | #  include "PTL/Globals.hh
"

I report it here in order to hope for a fix.
Comment 1 Peter Jansson 2020-12-07 15:04:07 CET
By compilation I mean compilation of my application using the Geant4 framework.
Comment 2 Ben Morgan 2020-12-07 15:10:31 CET
Please provide:

- OS/Version
- Compiler/Version
- CMake commands/options used to compile/install
- CMake/other commands/options used to compile the application
Comment 3 Peter Jansson 2020-12-07 15:43:48 CET
- OS/Version:

       Linux / Ubuntu 20.04.1 LTS

- Compiler/Version:

       g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0

- CMake commands/options used to compile/install:

       Geant4 installed using cmake with options as follows

       -DCMAKE_INSTALL_PREFIX=/usr/local/geant4.10.07 \
       -DGEANT4_USE_SYSTEM_EXPAT=OFF \
       -DGEANT4_BUILD_MULTITHREADED=ON \
       -DGEANT4_INSTALL_DATA=ON \
       -DGEANT4_USE_OPENGL_X11=ON \
       -DGEANT4_USE_RAYTRACER_X11=ON \
       -DGEANT4_USE_XM=ON

       (Followed by "make/make install".)

- CMake/other commands/options used to compile the application:

       Command line used when compiling my class that includes G4VPrimitiveScorer.hh:

       /usr/bin/c++  -DG4INTY_USE_XT -DG4UI_USE_TCSH -DG4UI_USE_XM -DG4VIS_USE_OPENGL -DG4VIS_USE_OPENGLX -DG4VIS_USE_OPENGLXM -DG4VIS_USE_RAYTRACERX -isystem /usr/local/geant4.10.07/include/Geant4  -W -Wall -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-variadic-macros -Wshadow -pipe -pthread -ftls-model=initial-exec -std=c++11  -O3 -DNDEBUG -fno-trapping-math -ftree-vectorize -fno-math-errno -pthread -std=gnu++17 -o MY_CLASS.o -c MY_CLASS.cpp

       (After this follows the error message reported.)
Comment 4 Ben Morgan 2020-12-07 15:47:30 CET
(In reply to Peter Jansson from comment #3)
> - CMake/other commands/options used to compile the application:
> 
>        Command line used when compiling my class that includes
> G4VPrimitiveScorer.hh:
> 
>        /usr/bin/c++  -DG4INTY_USE_XT -DG4UI_USE_TCSH -DG4UI_USE_XM
> -DG4VIS_USE_OPENGL -DG4VIS_USE_OPENGLX -DG4VIS_USE_OPENGLXM
> -DG4VIS_USE_RAYTRACERX -isystem /usr/local/geant4.10.07/include/Geant4  -W
> -Wall -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings
> -Wpointer-arith -Woverloaded-virtual -Wno-variadic-macros -Wshadow -pipe
> -pthread -ftls-model=initial-exec -std=c++11  -O3 -DNDEBUG
> -fno-trapping-math -ftree-vectorize -fno-math-errno -pthread -std=gnu++17 -o
> MY_CLASS.o -c MY_CLASS.cpp
> 
>        (After this follows the error message reported.)

How is this command line generated? Through CMake? Or a custom build? If a custom build, how are you constructing the above command line?
Comment 5 Peter Jansson 2020-12-07 15:52:02 CET
The above command is generated through cmake. Here are the some parts of the CMakeLists.txt file related to Geant4 and options for the compiler:

cmake_minimum_required(VERSION 3.16)
find_package(Geant4 REQUIRED ui_all vis_all)
include(${Geant4_USE_FILE})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Comment 6 Ben Morgan 2020-12-07 15:57:29 CET
How are the Geant4 libraries linked to the end application, through `target_link_libraries`? If so what commands?

To clarify, I _think_ I know what's going wrong, but I need to see the end-to-end invocation of CMake from finding Geant4 to how the libraries are linked. The issue is a missing include path in the compilation command and it's unclear _why_ this is missing.
Comment 7 Peter Jansson 2020-12-07 16:06:52 CET
My application fail before linking, since the error occurs when compiling the library including the MY_CLASS cpp file (below named "libproject"). These are the relevant "cmake link" commands, linking the main program (below called "main") with my library and the Geant 4 libraries.

add_library(libproject <many cpp files, including MY_CLASS.cpp>)
FIND_PACKAGE( Threads REQUIRED )
target_link_libraries( libproject PUBLIC Threads::Threads )

add_executable(main main.cpp)
target_link_libraries(main libproject ${Geant4_LIBRARIES})



Parts of MY_CLASS.h:

#ifndef MY_CLASS_h
#define MY_CLASS_h 1
#include "G4VPrimitiveScorer.hh"
#include "G4THitsMap.hh"
#include "G4Box.hh"
#include "G4PSDirectionFlag.hh"
class MY_CLASS : public G4VPrimitiveScorer
{
//... //
}
#endif
Comment 8 Ben Morgan 2020-12-07 16:34:25 CET
Thanks, the issue is now apparent. You should link the libproject target to the Geant4 libraries as well:

```
target_link_libraries( libproject PUBLIC Threads::Threads ${Geant4_LIBRARIES})
```

The `libproject` target is consuming the Geant4 libraries, and so should link to them to pick up the usage requirements (header paths for compilation, including those of dependencies).

The origin of the change is that in 10.7, a new library, PTL, is used to implement the tasking framework. The headers for this are installed in "<CMAKE_INSTALL_PREFIX>/include/PTL>", whilst the Geant4 ones are in "<CMAKE_INSTALL_PREFIX>/include/Geant4>". The former path is *not* added to `Geant4_INCLUDE_DIRS` as it's third-party, though we consider this a minor bug. Linking anything that uses Geant4 headers to the Geant4 targets (via `${Geant4_LIBRARIES}`) resolves this problem, and is also the correct way to use Geant4.
Comment 9 Peter Jansson 2020-12-07 16:50:06 CET
That did it. It was not easy to spot when living with a "usage error" that did not manifest itself in previous versions. Thank you.
Comment 10 Ben Morgan 2020-12-07 18:45:02 CET
I'm marking as "RESOLVED FIXED", though I mean that in the sense of "RESOLVED UNDERSTOOD". A noted, we do regard this as a bug so will be fixed in an upcoming patch.
Comment 11 Ben Morgan 2020-12-17 17:51:44 CET
Created attachment 651 [details]
Patch to resolve PTL include path errors outside of CMake

This patch has been applied to the master and 10.7 patch branches, so will be in 10.7.1 early next year. Attached here in the meantime for info and for packagers to apply if required.

Note that the issue can also be manually resolved in non-CMake build systems by adding the directory holding the `PTL` folder to the include path. In 10.7.0 this is guaranteed to be alongside the `Geant4` folder of headers:

+- CMAKE_INSTALL_INCLUDEDIR
   +- Geant4
   +- PTL

so can be derived from that.