Skip to content

Commit e1b3d5f

Browse files
bkanangomarifamd
authored andcommitted
[SWDEV-538483] Fix C++17 fs linking for GCC<9.0
Added check for GCC versions prior to 9.0 and link with libstdc++fs when needed. This fixes undefined symbols on older systems like Deb10 with GCC 8.3.0. Signed-off-by: Bindhiya Kanangot Balakrishnan <[email protected]> Signed-off-by: Galantsev, Dmitrii <[email protected]>
1 parent 1b027d1 commit e1b3d5f

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ set(CMAKE_CXX_STANDARD 17)
9090
set(CMAKE_CXX_STANDARD_REQUIRED ON)
9191
set(CMAKE_CXX_EXTENSIONS OFF)
9292

93+
# Link with stdc++fs for filesystem support (only for GCC < 9.0)
94+
set(FILESYSTEM_LIB "")
95+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
96+
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
97+
set(FILESYSTEM_LIB stdc++fs)
98+
message(STATUS "GCC ${CMAKE_CXX_COMPILER_VERSION} detected, linking with stdc++fs for filesystem support")
99+
endif()
100+
endif()
101+
93102
include(GNUInstallDirs)
94103

95104
option(BUILD_TESTS "Build test suite" OFF)

rocm_smi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ target_link_libraries(${ROCM_SMI_TARGET} PRIVATE
4949
rt
5050
Threads::Threads
5151
${CMAKE_DL_LIBS}
52+
${FILESYSTEM_LIB}
5253
)
5354
target_include_directories(${ROCM_SMI_TARGET} PRIVATE
5455
${CMAKE_CURRENT_SOURCE_DIR}

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ target_link_libraries(${AMD_SMI} PRIVATE
8888
rt
8989
Threads::Threads
9090
${CMAKE_DL_LIBS}
91+
${FILESYSTEM_LIB}
9192
)
9293
target_include_directories(${AMD_SMI} PRIVATE
9394
${CMAKE_CURRENT_SOURCE_DIR}

tests/amd_smi_test/CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ include_directories(${TEST} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${ROCM_INC_DIR}/..)
6161

6262
# Build rules
6363
add_executable(${TEST} ${tstSources} ${functionalSources})
64-
target_link_libraries(${TEST} ${AMD_SMI} GTest::gtest c stdc++ pthread)
65-
66-
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
67-
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9")
68-
target_link_libraries(${TEST} stdc++fs)
69-
endif()
64+
target_link_libraries(${TEST} ${AMD_SMI} GTest::gtest c stdc++ pthread ${FILESYSTEM_LIB})
7065

7166
# Install tests
7267
install(

0 commit comments

Comments
 (0)