WarpX icon indicating copy to clipboard operation
WarpX copied to clipboard

Building with libstdc++ 8 needs separate library providing std::filesystem?

Open kale-j opened this issue 5 months ago • 2 comments
trafficstars

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

[100%] Linking CXX executable bin/warpx.2d.MPI.OMP.DP.PDP.OPMD lib/libwarpx.2d.MPI.OMP.DP.PDP.OPMD.a(SemiImplicitEM.cpp.o): In function `PicardSolver::Define(WarpXSolverVec const&, ImplicitSolver*)': SemiImplicitEM.cpp:(.text._ZN12PicardSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_[_ZN12PicardSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_]+0x120): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()' SemiImplicitEM.cpp:(.text._ZN12PicardSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_[_ZN12PicardSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_]+0x130): undefined reference to `std::filesystem::__cxx11::path::parent_path() const' SemiImplicitEM.cpp:(.text._ZN12PicardSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_[_ZN12PicardSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_]+0x140): undefined reference to `std::filesystem::create_directories(std::filesystem::__cxx11::path const&)' lib/libwarpx.2d.MPI.OMP.DP.PDP.OPMD.a(SemiImplicitEM.cpp.o): In function `NewtonSolver::Define(WarpXSolverVec const&, ImplicitSolver*)': SemiImplicitEM.cpp:(.text._ZN12NewtonSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_[_ZN12NewtonSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_]+0x8a2): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()' SemiImplicitEM.cpp:(.text._ZN12NewtonSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_[_ZN12NewtonSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_]+0x8b5): undefined reference to `std::filesystem::__cxx11::path::parent_path() const' SemiImplicitEM.cpp:(.text._ZN12NewtonSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_[_ZN12NewtonSolverI14WarpXSolverVec14ImplicitSolverE6DefineERKS0_PS1_]+0xb64): undefined reference to `std::filesystem::create_directories(std::filesystem::__cxx11::path const&)' collect2: error: ld returned 1 exit status gmake[2]: *** [CMakeFiles/app_2d.dir/build.make:111: bin/warpx.2d.MPI.OMP.DP.PDP.OPMD] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:3671: CMakeFiles/app_2d.dir/all] Error 2 gmake: *** [Makefile:146: all] Error 2

kale-j avatar Jun 12 '25 16:06 kale-j

@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.

ax3l avatar Jun 17 '25 23:06 ax3l

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.

kale-j avatar Jun 18 '25 18:06 kale-j

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 )

ax3l avatar Jun 30 '25 21:06 ax3l

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.

ax3l avatar Jul 01 '25 17:07 ax3l