Failed to Compile the hwloc Dependency When Compiling TensorFlow 1.15.5
Symptom
When compiling TensorFlow 1.15.5, an error is reported stating "external/hwloc/hwloc/topology.c:45:10: fatal error: sys/sysctl.h: No such file or directory."

Key Process and Cause Analysis
Key error information: When compiling the hwloc dependency, an error is reported indicating that header file sys/sysctl.h is not found.
1 2 | external/hwloc/hwloc/topology.c:45:10: fatal error: sys/sysctl.h: No such file or directory 45 | #include <sys/sysctl.h> |
Root cause analysis: Header file sys/sysctl.h is deleted from glibc 2.32 and later, and sys/sysctl.h calls have been deleted from Linux kernel 5.5 and later. Because the kernel version is 5.10.0, an error is reported on the hwloc dependency.
Conclusion and Solution
- Open and edit the tensorflow/third_party/hwloc/BUILD.bazel file.
1vi tensorflow/third_party/hwloc/BUILD.bazel - Press i to enter the insert mode and delete line 113.
"#undef HAVE_SYS_SYSCTL_H": "#define HAVE_SYS_SYSCTL_H 1",
Before deletion:

After deletion:

- Press Esc, type :wq!, and press Enter to save the file and exit.
- Recompile TensorFlow.
1bazel build --config=v1 --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" //tensorflow/tools/pip_package:build_pip_package
Parent topic: Troubleshooting