如何强制 Bazel 将库路径设置为所需的路径?
Posted
技术标签:
【中文标题】如何强制 Bazel 将库路径设置为所需的路径?【英文标题】:How to force Bazel to set libraries path to a desired one? 【发布时间】:2017-10-30 05:51:24 【问题描述】:假设我们有一个非常具体的 GCC,我们想用它构建 tensorflow
我们出口需要的东西:
export CC=/opt/gcc-4.9.3/bin/gcc
export CXX=/opt/gcc-4.9.3/bin/g++
export LIBRARY_PATH=/opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64/:$LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64/:$LD_LIBRARY_PATH
bazel build //tensorflow:libtensorflow.so --action_env=LIBRARY_PATH --action_env=LD_LIBRARY_PATH
我们经营 Bazel
bazel build //tensorflow:libtensorflow.so --action_env=LIBRARY_PATH --action_env=LD_LIBRARY_PATH --verbose_failures
WARNING: Output base '/home/xxx/.cache/bazel/_bazel_xxx/19df47f8ddcc70ebf80eed36c3acb5a1' is on NFS. This may lead to surprising failures and undetermined behavior.
WARNING: /home/xxx/tensorflow/tensorflow/core/BUILD:1787:1: in includes attribute of cc_library rule //tensorflow/core:framework_headers_lib: '../../external/nsync/public' resolves to 'external/nsync/public' not below the relative path of its package 'tensorflow/core'. This will be an error in the future. Since this rule was created by the macro 'cc_header_only_library', the error might have been caused by the macro implementation in /home/xxx/tensorflow/tensorflow/tensorflow.bzl:1048:30.
INFO: Found 1 target...
ERROR: /home/xxx/.cache/bazel/_bazel_xxx/19df47f8ddcc70ebf80eed36c3acb5a1/external/nasm/BUILD.bazel:8:1: Linking of rule '@nasm//:nasm' failed (Exit 1): crosstool_wrapper_driver_is_not_gcc failed: error executing command
(cd /home/xxx/.cache/bazel/_bazel_xxx/19df47f8ddcc70ebf80eed36c3acb5a1/execroot/org_tensorflow && \
exec env - \
LD_LIBRARY_PATH=:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64 \
PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/local/bin:/var/cfengine/bin:/usr/local/cuda/bin:/home/xxx/.local/bin:/home/xxx/bin \
PWD=/proc/self/cwd \
external/local_config_cuda/crosstool/clang/bin/crosstool_wrapper_driver_is_not_gcc -o bazel-out/host/bin/external/nasm/nasm -Wl,-no-as-needed -B/usr/bin/ -pie -Wl,-z,relro,-z,now -no-canonical-prefixes -pass-exit-codes '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -Wl,--gc-sections -Wl,-S -Wl,@bazel-out/host/bin/external/nasm/nasm-2.params).
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
Target //tensorflow:libtensorflow.so failed to build
INFO: Elapsed time: 17.445s, Critical Path: 0.72s
但它无法检测到我们导出的LIBRARY_PATH
和LD_LIBRARY_PATH
中存在的-lgcc_s
。那么如何将我们的LIBRARY_PATH
强制到我们的库所依赖的库上呢?
【问题讨论】:
【参考方案1】:像--linkopt=-L/opt/gcc-4.9.3/lib64/gcc/x86_64-fedoraunited-linux-gnu/lib64/
这样的操作应该可以工作。
【讨论】:
以上是关于如何强制 Bazel 将库路径设置为所需的路径?的主要内容,如果未能解决你的问题,请参考以下文章