| Summary: | Version 10.7: G4Profiler.icc: PTL/Globals.hh: No such file or directory | ||
|---|---|---|---|
| Product: | Geant4 | Reporter: | Peter Jansson <webmaster> |
| Component: | cmake | Assignee: | Ben Morgan <Ben.Morgan> |
| Status: | CLOSED FIXED | ||
| Severity: | normal | ||
| Priority: | P4 | ||
| Version: | other | ||
| Hardware: | All | ||
| OS: | Linux | ||
| Attachments: | Patch to resolve PTL include path errors outside of CMake | ||
By compilation I mean compilation of my application using the Geant4 framework. Please provide: - OS/Version - Compiler/Version - CMake commands/options used to compile/install - CMake/other commands/options used to compile the application - 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.)
(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? 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)
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. 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
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.
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. 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. 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.
|
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.