From 4b5769439ee274c6df96c80e8c74bea221d36d74 Mon Sep 17 00:00:00 2001 From: Gabriel Ferreira Date: Sat, 15 Apr 2023 11:48:06 -0300 Subject: [PATCH] build: explicitly link stdc++fs on GCC 8 --- build-support/custom-modules/ns3-module-macros.cmake | 4 +++- build-support/macros-and-definitions.cmake | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build-support/custom-modules/ns3-module-macros.cmake b/build-support/custom-modules/ns3-module-macros.cmake index 1e3e38a99..4dd9f6d75 100644 --- a/build-support/custom-modules/ns3-module-macros.cmake +++ b/build-support/custom-modules/ns3-module-macros.cmake @@ -104,7 +104,9 @@ function(build_lib) ) endif() - if(NOT FILESYSTEM_LIBRARY_IS_LINKED) + if((NOT FILESYSTEM_LIBRARY_IS_LINKED) OR (${GCC} AND ${GCC8})) + # The GCC8 alternative is necessary since when installed alongside newer + # releases, the incorrect shared library can end up being linked. list(APPEND BLIB_LIBRARIES_TO_LINK -lstdc++fs) endif() diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index e5e74e567..c4afaf976 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -202,6 +202,7 @@ if(CLANG) endif() set(GCC FALSE) +set(GCC8 FALSE) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${GNU_MinVersion}) message( @@ -209,6 +210,12 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") "GNU ${CMAKE_CXX_COMPILER_VERSION} ${below_minimum_msg} ${GNU_MinVersion}" ) endif() + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0") + # This block is used to identify if GCC8 is being used. In this case, we + # want to explicitly link stdc++fs, which is done in + # ns3-module-macros.cmake. + set(GCC8 TRUE) + endif() set(GCC TRUE) add_definitions(-fno-semantic-interposition) if(${NS3_COLORED_OUTPUT} OR "$ENV{CLICOLOR}")