From 3f24ef33ab6bd52c2a3c62846b31cf07b2e2cbb4 Mon Sep 17 00:00:00 2001 From: Charles Volzka <42243335+cjvolzka@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:43:15 -0500 Subject: [PATCH] Prevent crash on import after GCC 8 builds (#6048) ### Description Possible fix for https://github.com/onnx/onnx/issues/6047 based on https://stackoverflow.com/questions/33149878/experimentalfilesystem-linker-error/33159746#33159746 ### Motivation and Context I'm not a cmake expert so there may be a better way to do this. This did allow me to build ONNX 1.16 on RHEL 8. --------- Signed-off-by: Charles Volzka Signed-off-by: Charles Volzka <42243335+cjvolzka@users.noreply.github.com> Co-authored-by: Thiago Crepaldi Co-authored-by: G. Ramalingam --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c26b312b15b..71c2f54752f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -587,6 +587,11 @@ if(BUILD_ONNX_PYTHON) target_link_libraries(onnx_cpp2py_export PRIVATE "-Wl,--whole-archive" $ "-Wl,--no-whole-archive") + # Prevent "undefined symbol: _ZNSt10filesystem7__cxx114path14_M_split_cmptsEv" + # (std::filesystem::__cxx11::path::_M_split_cmpts()) on gcc 8 + if (CMAKE_CXX_STANDARD EQUAL 17 AND CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) + target_link_libraries(onnx_cpp2py_export PRIVATE "-lstdc++fs") + endif() set_target_properties(onnx_cpp2py_export PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL") endif()