tensorflow: build error: undefined reference to `clock_gettime'
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow): No
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Linux CentOS 6.9
- TensorFlow installed from (source or binary): source
- TensorFlow version (use command below): master branch: the latest version
- Python version: 2.7
- Bazel version (if compiling from source): 0.8.0
- GCC/Compiler version (if compiling from source): 4.8.2
- CUDA/cuDNN version: No
- GPU model and memory: No
- Exact command to reproduce: bazel build --linkopt=-lrt -c opt --verbose_failures //tensorflow:libtensorflow_cc.so
Describe the problem
I tried to build the tensor flow c++ lib from the source code, but it failed.
Source code / logs
ERROR: /home/baigang/Projects/xylib/thirdparty/tenserflow/package/tensorflow/tensorflow/cc/BUILD:422:1: Linking of rule ‘//tensorflow/cc:ops/random_ops_gen_cc’ failed (Exit 1): gcc failed: error executing command
(cd /home/baigang/.cache/bazel/_bazel_baigang/d3e5550086b82aa173767408d0f485e7/execroot/org_tensorflow &&
exec env -
PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/baigang/bin
PWD=/proc/self/cwd
/usr/bin/gcc -o bazel-out/host/bin/tensorflow/cc/ops/random_ops_gen_cc ‘-Wl,-rpath,$ORIGIN/…/…/…/_solib_k8/_U_S_Stensorflow_Scc_Cops_Srandom_Uops_Ugen_Ucc___Utensorflow’ -Lbazel-out/host/bin/_solib_k8/_U_S_Stensorflow_Scc_Cops_Srandom_Uops_Ugen_Ucc___Utensorflow ‘-Wl,-rpath,$ORIGIN/,-rpath,$ORIGIN/…,-rpath,$ORIGIN/…/…’ -pthread -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -B/usr/bin -pass-exit-codes -Wl,–gc-sections -Wl,-S -Wl,@bazel-out/host/bin/tensorflow/cc/ops/random_ops_gen_cc-2.params)
bazel-out/host/bin/_solib_k8/_U_S_Stensorflow_Scc_Cops_Srandom_Uops_Ugen_Ucc___Utensorflow/libtensorflow_framework.so: undefined reference to `clock_gettime’
collect2: error: ld returned 1 exit status
Target //tensorflow:libtensorflow_cc.so failed to build
INFO: Elapsed time: 418.738s, Critical Path: 35.11s
FAILED: Build did NOT complete successfully
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (5 by maintainers)
Commits related to this issue
- Add -lrt to linkflags Fixes compilation on e.g. older CentOS, see for details #15129 — committed to tensorflow/tensorflow by Flamefire 4 years ago
- Add -lrt to linkflags Fixes compilation on e.g. older CentOS, see for details #15129 — committed to Flamefire/tensorflow by Flamefire 4 years ago
I had the same issue. To compile under one older linux Centos 6.7, i edited the tensorflow.bzl file and added manually at some linkopts field -lrt near -lm. Then compilation was successfull. Hope this help.
I had the same error on CentOS 6.9, but was able to get it to build successfully by adding
-lrt
to the linking options on lines 267 and 1267 intensorflow.bzl
. A small patch file with the changes is here.Hello, I am facing the similar issue but the link you provided above land me to “page not found”. Could you please help provide the command? Thanks!!
For those arriving via Google in future, the following
-lrt
additions allowed tensorflow r1.12 to build for me on CentOS7: https://gist.github.com/joshpencheon/bd4299223c26.