Cannot compile bazel to use a local gcc
Hi, I am bounded to an old machine which I cannot update. I have compiled a gcc-5.2 local version in my home. I have modified the tools/cpp/CROSSTOOL to use the ~/local/bin/gcc and cpp However, when I try to compile bazel I get the following error: .cache/bazel/_bazel/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by .cache/bazel/_bazel/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles ERROR: bazel/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/BUILD:1:1: Creating runfiles tree bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass/GenClass.runfiles failed: build-runfiles failed: error executing command .cache/bazel/_bazel/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles ... (remaining 2 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1. Target //src:bazel failed to build
Hello,
Try to modify tools/cpp/CROSSTOOL file and export CXX and CC environment variable
Hi, I had already modified tools/cpp/CROSSTOOL as well as exported CC and CXX and added to LD_LIBARY_PATH variable the lib64
Thanks,
Can you run that build-runfiles binary from the shell directly?
Bazel isn't going to pass the LD_LIBRARY_PATH variable onto the processes it runs, which might also be the issue. Adding something along the lines of compiler_flag: "-Wl,-rpath,/home/you/local/lib64" (using the path you have to add to LD_LIBRARY_PATH) might fix it.
If you run Bazel with --verbose_failures, it will print out a shell command which runs the failing command in the appropriate environment, which can be helpful for debugging issues like this.
Hi, thanks, adding compiler_flag or link_flag doesn't seem to help. How do I add the --verbose_failures flag to ./compile.sh ?
export BAZEL_ARGS='--verbose_failures'
Hi, if I set the BAZEL_ARGS I get this error instead : Loading of target '@bazel_tools//tools/jdk:ijar' failed; build aborted: no such target '@bazel_tools//tools/jdk:ijar': target 'ijar' not declared in package 'tools/jdk' defined by .cache/bazel/_bazel/dcfa5b4604a3b008ad5ed0a566717120/external/bazel_tools/tools/jdk/BUILD. If I unset it I get back the GLIBCXX error. Any idea how to compile it ?
oh yes sorry for that. Better do:
echo 'build --verbose_failures' >/tmp/bazelrc
export BAZELRC=/tmp/bazelrc
Hi, the command that fails is this one: (cd $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel && exec env - $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles) And if I do this: (cd $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel && exec env - LD_LIBRARY_PATH=$HOME/local.gcc-4.8.1/lib64:$HOME/jdk1.8.0_65/lib:/usr/local/cuda-7.0/lib64 $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles) Then it links correctly for this step. Is there a way to enforce this for all ./compile run ?
Thanks,
You have to add your libraries path ($HOME/local.gcc-4.8.1/lib64:$HOME/jdk1.8.0_65/lib:/usr/local/cuda-7.0/lib64) at the correct place in your ./tools/cpp/CROSSTOOL
I am really sorry for the mess. It should be easier but I had no time yet to work on our configuration detection system.
On Fri, Nov 20, 2015 at 1:25 PM Jesus Andres Ferrer < [email protected]> wrote:
Hi, the command that fails is this one: (cd $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel && exec env - $HOME/.cache/bazel/bazel $USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/
_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles) And if I do this: (cd $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel && exec env - LD_LIBRARY_PATH=$HOME/local.gcc-4.8.1/lib64:$HOME/jdk1.8.0_65/lib:/usr/local/cuda-7.0/lib64 $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/tools/android/java/com/google/devtools/build/android/ziputils/all.runfiles) Then it links correctly for this step. Is there a way to enforce this for all ./compile run ?
Thanks,
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/629#issuecomment-158382434.
Hi, no worries and thanks for the help. Could you be a little more specific ? Which is the correct place of ./tools/cpp/CROSSTOOL ? Thanks :+1:
I guess adding those line in the "local-linux" toolchain is the correct way to go (I am not that familiar with the CROSSTOOL file itself):
linker_flag: "-L$HOME/local.gcc-4.8.1/lib64"
linker_flag: "-L$HOME/jdk1.8.0_65/lib"
linker_flag: "-L$HOME/local/cuda-7.0/lib64"
With $HOME replaced by the good path.
Hi Thanks, Unfortunately, I had already included those flags into the CROSSTOOL and local-linx toolchain, and still takes the wrong libstdc++. /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found I am sure it is local-linux, because now it takes the right compiler (otherwise the error is at compile time), and I had to modify tool_path { name: "gcc" path: "/path/to/gcc" }
Thanks !
ok I will give you a hack for quick resolution:
cat <<EOF >tools/cpp/gcc_wrapper.sh
#!/bin/bash
set -e
LD_LIBRARY_PATH=$HOME/local.gcc-4.8.1/lib64:$HOME/jdk1.8.0_65/lib:/usr/local/cuda-7.0/lib64 $HOME/local/bin/gcc "$@"
EOF
And replace the tool_path for 'gcc' to 'gcc_wrapper.sh' This should use the shell script instead of gcc, that's what we do to rewrite argument for Darwin's clang.
Hi, Unfortunately, this doesn't solve the problem. The gcc_wrapper.sh is used, but still there is linking errors. The error now is this: (cd $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel && exec env - $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/JavaBuilder.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/JavaBuilder.runfiles)
The trick used above (env - LD_LIBRARY_PATH = .... ) also solves the problem of this comand. However, despite he CROSSTOOL now has: tool_path { name: "gcc" path: "gcc_wrapper.sh" } It is not correctly linked when called within ./compile.sh
Thanks,
That's not an error message, that a java compilation command-line. Can you use a gist to give the full output?
On Fri, Nov 20, 2015 at 4:11 PM Jesus Andres Ferrer < [email protected]> wrote:
Hi, Unfortunately, this doesn't solve the problem. The gcc_wrapper.sh is used, but still there is linking errors. The error now is this: (cd $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel && exec env - $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/JavaBuilder.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/JavaBuilder.runfiles)
The trick used above also solves the problem. The CROSSTOOL now has: tool_path { name: "gcc" path: "gcc_wrapper.sh" }
Thanks,
— Reply to this email directly or view it on GitHub https://github.com/bazelbuild/bazel/issues/629#issuecomment-158426751.
Hi, sorry, I meant the error is the same, and is output in that command. The error is still this:
$HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles) ERROR: $HOME/bazel/src/java_tools/buildjar/BUILD:3:1: Creating runfiles tree bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/JavaBuilder.runfiles failed: build-runfiles failed: error executing command: (cd $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel && exec env - $HOME/.cache/bazel/bazel$USER/dcfa5b4604a3b008ad5ed0a566717120/bazel/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/JavaBuilder.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/java_tools/buildjar/JavaBuilder.runfiles)
The command is the pasted above
@casiciaco The build-runfiles has to be compiled statically with libstdc++.a, otherwise when it runs internally it will require properly set LD_LIBRARY_PATH which is not possible in bazel.
Which step of the compile.sh script it is?
I supposed it is in the "Compiling Bazel with Bazel" one. In that case, that means that https://github.com/bazelbuild/bazel/blob/master/scripts/bootstrap/compile.sh#L328 compiles with the wrong gcc.
Maybe simply trying to build from a clean tree with redoing the correct modification in the CROSSTOOL file and exporting the correct value.
you can try to run compile.sh compile and then unzip output/bazel build-runfiles; ./build-runfiles to see if you get the same error.
Hi,
I cloned the bazel git repo.
I fixed CROSSTOOL as discussed above.
I run ./compile.sh compile and got the same problem stated above with this command:
$HOME/.cache/bazel/_bazel_$USER//97d5192f7b8aedf754ab6e2587dbb030/bazel.2/_bin/build-runfiles: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.14' not found (required by $HOME/.cache/bazel/_bazel_j$USER/97d5192f7b8aedf754ab6e2587dbb030/bazel.2/_bin/build-runfiles)
ERROR: $HOME/bazel.2/src/java_tools/singlejar/BUILD:19:1: Creating runfiles tree bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles failed: build-runfiles failed: error executing command
(cd $HOME/.cache/bazel/_bazel_$USER/97d5192f7b8aedf754ab6e2587dbb030/bazel.2 && \
exec env - \
$HOME/.cache/bazel/_bazel_$USER/97d5192f7b8aedf754ab6e2587dbb030/bazel.2/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles)
Then I executed :
unzip unzip output/bazel build-runfiles
And then I run (with the current term environment which includes LD_LIBARY_FLAGS, CXX, CC etc correctly set):
./build-runfiles bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles
This last command worked ok.
I guess this is similar to add env - LD_LIBRARY_PATH=... to the failed command since it correctly imports the environment variables. Also if I execute directly in the prompt (w/ correct environment):
$HOME/.cache/bazel/_bazel_$USER/97d5192f7b8aedf754ab6e2587dbb030/bazel.2/_bin/build-runfiles bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles_manifest bazel-out/local_linux-fastbuild/bin/src/java_tools/singlejar/SingleJar.runfiles
It also works. The part of the command that makes things go wrong is the env - Is there a way to fix/hack the compilation ?
Oh gosh I see. I don't thinks that's possible :(.
@lberki @ulfjack Any idea on how to tweak the command environment to fix the LD_LIBRARY_PATH?