Skip to content

Commit

Permalink
Fix old GCC ABI check in CMake package config (pytorch#72081)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#72081

This PR fixes the libstdc++ ABI check in CMake package configuration file (i.e. `TorchConfig.cmake`) The `_GLIBCXX_USE_CXX11_ABI` flag is a property of `libstdc++`, not GNU compiler collection. In its current form C++ libraries built with Clang on Linux fail since the `torch` CMake target propagates `_GLIBCXX_USE_CXX11_ABI` only when used with gcc.
ghstack-source-id: 148056323

Test Plan: Built a dummy C++ library that depends on libtorch with both gcc and clang on Linux

Reviewed By: malfet

Differential Revision: D33899849

fbshipit-source-id: 3e933b2c7a17d1fba086caa8aaec831223760882
(cherry picked from commit 41d18c6)
  • Loading branch information
cbalioglu authored and pytorchmergebot committed Feb 1, 2022
1 parent c93d6f9 commit 1cc824e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion caffe2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ endif()
endif()

# XXX This ABI check cannot be run with arm-linux-androideabi-g++
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
if(DEFINED GLIBCXX_USE_CXX11_ABI)
message(STATUS "_GLIBCXX_USE_CXX11_ABI is already defined as a cmake variable")
else()
Expand Down
4 changes: 2 additions & 2 deletions cmake/TorchConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ if(@USE_CUDA@)
list(APPEND TORCH_LIBRARIES ${TORCH_CUDA_LIBRARIES})
endif()

# When we build libtorch with the old GCC ABI, dependent libraries must too.
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# When we build libtorch with the old libstdc++ ABI, dependent libraries must too.
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(TORCH_CXX_FLAGS "-D_GLIBCXX_USE_CXX11_ABI=@GLIBCXX_USE_CXX11_ABI@")
endif()

Expand Down

0 comments on commit 1cc824e

Please sign in to comment.