WarpX
WarpX copied to clipboard
Building with libstdc++ 8 needs separate library providing std::filesystem?
Description
Building the latest version on a linux workstation (RHEL 8) with libstdc++ 8.5 fails during linking.
Shortened error message
undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
This appears to be related to std::filesystem being included in stdc++fs (rather than in stdc++ itself) for old versions of gcc. As far as I know, this is not linked ordinarily, as it is not required by gcc > 8.
EDIT: Potential fix
Adding the following to CMakeLists.txt fixes this on my system (shamelessly taken from a post on cmake.org)
function( set_required_build_settings_for_GCC8 )
# link with libstdc++fs.a when using GCC 8
link_libraries( "$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_LESS:$<CXX_COMPILER_VERSION>,9.0>>:-lstdc++fs>" )
endfunction()
set_required_build_settings_for_GCC8()
System information
Please check all relevant boxes and provide details.
- Operating system:
- Linux: RHEL 8, libstdc++ 8.5
- Version of WarpX: latest
- Installation method:
- From source with CMake:
- cmake -S . -B build -DWarpX_COMPUTE=OMP -DWarpX_DIMS="2" -DWarpX_QED=OFF -DWarpX_EB=OFF
Full error message
@kale-j thanks for the report! Correct, I mentioned this to @dpgrote when he introduced a dependency on std::filesystem. Indeed in old compilers, one had to manually link it.
We thus pushed our requirements up to GCC 9.1+ with the change (released in 2022). But we do not check for it actively to warn about it with old systems.
In your case, is there a way to get a (slightly) newer GCC on that system, e.g., as a module, or use LLVM/Clang, or update to RHEL 9?
I agree, we should either add a work-around like the one you suggested while RHEL8 is still around, or at least throw a warning/error during configuration phase.
I'm surprised I got away with it for 3 years!
In theory there should be several different ways I can install a newer version of gcc alongside gcc 8.x. It'll take some time for me to sort out which option will be the least terrible. I can keep you posted if you're interested, or we can close this.
I mean we only added this end of last year via #5464
@dpgrote do you mind refactoring the std::filesystem usage out for now? AMReX should have all the helpers we need for the simple path manipulations we have in #5464 (cc @WeiqunZhang )
Hi @kale-j, can you please check if #5990 fixes the problem for you?
I added an extra compile-time check and targeted link of the dependency for older GCC.