File tree Expand file tree Collapse file tree 6 files changed +33
-2
lines changed Expand file tree Collapse file tree 6 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -231,8 +231,14 @@ def run(self):
231231 '-fno-strict-aliasing' ]
232232if os .getenv ('PYTORCH_BINARY_BUILD' ) and platform .system () == 'Linux' :
233233 print ('PYTORCH_BINARY_BUILD found. Static linking libstdc++ on Linux' )
234- extra_compile_args += ['-static-libstdc++' ]
235- extra_link_args += ['-static-libstdc++' ]
234+ # get path of libstdc++ and link manually.
235+ # for reasons unknown, -static-libstdc++ doesn't fully link some symbols
236+ CXXNAME = 'g++'
237+ if os .getenv ('CXX' ):
238+ CXXNAME = os .getenv ('CXX' )
239+ path = subprocess .check_output ([CXXNAME , '-print-file-name=libstdc++.a' ])
240+ path = path .replace ('\n ' , '' )
241+ extra_link_args += [path ]
236242
237243cwd = os .path .dirname (os .path .abspath (__file__ ))
238244lib_path = os .path .join (cwd , "torch" , "lib" )
Original file line number Diff line number Diff line change @@ -58,6 +58,11 @@ IF(NOT THNN_LIBRARIES)
5858ENDIF (NOT THNN_LIBRARIES)
5959MESSAGE (STATUS "THNN_LIBRARIES: ${THNN_LIBRARIES} " )
6060
61+ IF ($ENV{TH_BINARY_BUILD} )
62+ MESSAGE (STATUS "TH_BINARY_BUILD detected. Statically linking libstdc++" )
63+ SET (CMAKE_CXX_FLAGS "-static-libstdc++ ${CMAKE_CXX_FLAGS} " )
64+ ENDIF ()
65+
6166IF (NO_CUDA)
6267 MESSAGE (STATUS "ignoring CUDA" )
6368 SET (CUDA_FLAG -n)
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
3939 SET (CMAKE_CXX_STANDARD 11)
4040endif ()
4141
42+ IF ($ENV{TH_BINARY_BUILD} )
43+ MESSAGE (STATUS "TH_BINARY_BUILD detected. Statically linking libstdc++" )
44+ SET (CMAKE_CXX_FLAGS "-static-libstdc++ ${CMAKE_CXX_FLAGS} " )
45+ ENDIF ()
46+
4247INCLUDE_DIRECTORIES (${CUDA_INCLUDE_DIRS} )
4348INCLUDE_DIRECTORIES ("${CUDA_SDK_ROOT_DIR} /common/inc" )
4449
Original file line number Diff line number Diff line change @@ -29,6 +29,11 @@ IF(NOT CUDA_FOUND)
2929 FIND_PACKAGE (CUDA 6.5 REQUIRED)
3030ENDIF ()
3131
32+ IF ($ENV{TH_BINARY_BUILD} )
33+ MESSAGE (STATUS "TH_BINARY_BUILD detected. Statically linking libstdc++" )
34+ SET (CMAKE_CXX_FLAGS "-static-libstdc++ ${CMAKE_CXX_FLAGS} " )
35+ ENDIF ()
36+
3237# Detect CUDA architecture and get best NVCC flags
3338IF (NOT COMMAND CUDA_SELECT_NVCC_ARCH_FLAGS OR MSVC )
3439 INCLUDE (${CMAKE_CURRENT_SOURCE_DIR} /cmake/select_compute_arch.cmake)
Original file line number Diff line number Diff line change @@ -83,6 +83,11 @@ ENDIF()
8383
8484ADD_DEFINITIONS (-D_THD_CORE=1)
8585
86+ IF ($ENV{TH_BINARY_BUILD} )
87+ MESSAGE (STATUS "TH_BINARY_BUILD detected. Statically linking libstdc++" )
88+ SET (CMAKE_CXX_FLAGS "-static-libstdc++ ${CMAKE_CXX_FLAGS} " )
89+ ENDIF ()
90+
8691# Can be compiled standalone
8792IF (NOT THD_INSTALL_BIN_DIR OR NOT THD_INSTALL_LIB_DIR OR NOT THD_INSTALL_INCLUDE_DIR)
8893 SET (THD_INSTALL_BIN_DIR "bin" CACHE PATH "THD install binary subdirectory" )
Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ ELSE()
6060 ENDIF ()
6161ENDIF ()
6262
63+ IF ($ENV{TH_BINARY_BUILD} )
64+ MESSAGE (STATUS "TH_BINARY_BUILD detected. Statically linking libstdc++" )
65+ SET (CMAKE_CXX_FLAGS "-static-libstdc++ ${CMAKE_CXX_FLAGS} " )
66+ ENDIF ()
67+
6368# Can be compiled standalone
6469IF (NOT THPP_INSTALL_BIN_DIR OR NOT THPP_INSTALL_LIB_DIR OR NOT THPP_INSTALL_INCLUDE_DIR)
6570 SET (THPP_INSTALL_BIN_DIR "bin" CACHE PATH "THPP install binary subdirectory" )
You can’t perform that action at this time.
0 commit comments