Link to gcc_s and gcc if compiler is GCC version 5 (#17849)
authorYihong Wang <yh.wang@ibm.com>
Thu, 12 Apr 2018 19:59:48 +0000 (12:59 -0700)
committerJonathan Hseu <vomjom@vomjom.net>
Thu, 12 Apr 2018 19:59:48 +0000 (12:59 -0700)
When using cmake and GCC 5.4 to build tensorflow in Ubuntu 16.04,
the following error message would show up when loading
_pywrap_tensorflow_internal.so:
```
_pywrap_tensorflow_internal.so: undefined symbol: __cpu_model
```

The root cause is the same to this issue:
https://github.com/tensorflow/tensorflow/issues/9593

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
tensorflow/contrib/cmake/tf_python.cmake

index ded15b4..1c3206f 100755 (executable)
@@ -586,6 +586,12 @@ add_library(pywrap_tensorflow_internal SHARED
     ${pywrap_tensorflow_deffile}
 )
 
+# There is a bug in GCC 5 resulting in undefined reference to a __cpu_model function when
+# linking to the tensorflow library. Adding the following libraries fixes it.
+if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
+    target_link_libraries(pywrap_tensorflow_internal PRIVATE gcc_s gcc)
+endif()
+
 if(WIN32)
     add_dependencies(pywrap_tensorflow_internal pywrap_tensorflow_internal_static)
 endif(WIN32)