Bazel build error: gcc failed: error executing command

babuya: <p>Hi, my libtorch version is <em>libtorch-cxx11-abi-shared-with-deps-1.10.2+cu113.zip</em>.<br>
I have build an example successfully with CMake before.<br>
Now I want to build with bazel. I have followed <a href="https://github.com/bazelbuild/bazel/issues/10803" class="inline-onebox" rel="noopener nofollow ugc">cc_library() import precompiled shared libraries to a temp directory caused error while loading shared libraries · Issue #10803 · bazelbuild/bazel · GitHub</a></p>
<p>the project tree:</p>
<pre><code class="lang-auto">example
├── BUILD
└── torch-example.cc
libtorch
├── BUILD
├── include
├── lib
WORKSPACE
</code></pre>
<p>the libtorch BUILD file:</p>
<pre><code class="lang-auto">package(
    default_visibility = ["//visibility:public"],
)
licenses(["notice"])  # BSD
exports_files(["LICENSE"])

TORCH_HEADERS = glob([
    "include/**/*.h",
    "include/*.h",
])

TORCH_LIBRARIES = [
    "lib/libtorch.so",
    "lib/libc10_cuda.so",
    "lib/libc10.so",
    "lib/libcudart-a7b20f20.so.11.0",
    "lib/libnvToolsExt-24de1d56.so.1",
]

cc_library(
    name = "libtorch",
    srcs = TORCH_LIBRARIES,
    hdrs = TORCH_HEADERS,
    includes = ["include", "include/torch/csrc/api/include"],
    linkopts = ["-lpthread"],
)
</code></pre>
<p>the example BUILD file:</p>
<pre><code class="lang-auto">cc_binary(
    name = "torch-example",
    srcs = ["torch-example.cc"],
    deps = [
        "//libtorch:libtorch",
    ],
)
</code></pre>
<p>However, when I ran<br>
<code>bazel build --verbose_explanations --color=yes --curses=yes --verbose_failures -s //example:torch-example</code></p>
<p>it turned out</p>
<pre><code class="lang-auto">ERROR: /data2/ssz/bazel_torch/example/BUILD:3:10: Compiling example/torch-example.cc failed: (Exit 1): gcc failed: error executing command 
  (cd /home/bhu/.cache/bazel/_bazel_bhu/7377f4c691144c42eb6d6f4f8f6daf79/sandbox/linux-sandbox/8/execroot/__main__ &amp;&amp; \
  exec env - \
    LD_LIBRARY_PATH=/home/bhu/catkin_ws/devel/lib \
    PATH=/home/bhu/.local/bin:/home/bhu/bin:/home/bhu/google-cloud-sdk/bin:/home/bhu/anaconda3/bin:/home/bhu/anaconda3/condabin:/home/bhu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/bhu/bin:/home/bhu/bin \
    PWD=/proc/self/cwd \
  /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -MD -MF bazel-out/k8-fastbuild/bin/example/_objs/torch-example/torch-example.pic.d '-frandom-seed=bazel-out/k8-fastbuild/bin/example/_objs/torch-example/torch-example.pic.o' -fPIC -iquote . -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -isystem libtorch/include -isystem bazel-out/k8-fastbuild/bin/libtorch/include -isystem libtorch/include/torch/csrc/api/include -isystem bazel-out/k8-fastbuild/bin/libtorch/include/torch/csrc/api/include -fno-canonical-system-headers -Wno-builtin-macro-redefined '-D__DATE__="redacted"' '-D__TIMESTAMP__="redacted"' '-D__TIME__="redacted"' -c example/torch-example.cc -o bazel-out/k8-fastbuild/bin/example/_objs/torch-example/torch-example.pic.o)
Execution platform: @local_config_platform//:host
</code></pre>
<p>It really make me confused. Could anyone tell me what may I do?<br>
Thanks.</p>