编程技术网

关注微信公众号,定时推送前沿、专业、深度的编程技术资料。

 找回密码
 立即注册

QQ登录

只需一步,快速开始

极客时间

使用自定义Clang + Libc ++(而不是stdlibc ++)编译Tensorflow:Compiling Tensorflow with a custom Clang + Libc++ (instead of stdlibc++)

Maarten Raaijm Tensorflow 2022-5-10 11:54 8人围观

腾讯云服务器
使用自定义Clang + Libc ++(而不是stdlibc ++)编译Tensorflow的处理方法

我正在尝试使用自定义clang/llvm工具链并使用clang的本机libc ++编译tensorflow(而不是借用Gcc的stdlibc ++).

I am trying to compile tensorflow with a custom clang/llvm toolchain and using clang's native libc++ (instead of borrowing Gcc's stdlibc++).

似乎bazel plain假设每个clang都将使用Gcc的库,因为出现以下错误:

It looks like bazel plain assumes that every clang will use Gcc's libraries because I get these errors:

$ bazel build --cxxopt=-std=c++11 --cxxopt=-stdlib=libc++ tensorflow:libtensorflow.so INFO: Found 1 target... INFO: From Compiling external/protobuf/src/google/protobuf/compiler/js/embed.cc [for host]: external/protobuf/src/google/protobuf/compiler/js/embed.cc:37:12: warning: unused variable 'output_file' [-Wunused-const-variable] const char output_file[] = "well_known_types_embed.cc"; ^ 1 warning generated. ERROR: /home/hbucher/.cache/bazel/_bazel_hbucher/ad427c7fddd5b68de5e1cfaa7cd8c8cc/external/com_googlesource_code_re2/BUILD:11:1: undeclared inclusion(s) in rule '@com_googlesource_code_re2//:re2': this rule is missing dependency declarations for the following files included by 'external/com_googlesource_code_re2/re2/bitstate.cc': '/home/hbucher/install/include/c++/v1/stddef.h' '/home/hbucher/install/include/c++/v1/__config' 

我尝试侵入bazel中的tools/cpp/CROSSTOOL,因为一些帖子建议添加该行

I tried to hack into tools/cpp/CROSSTOOL inside bazel as some posts suggested to add the line

cxx_builtin_include_directory: "/home/hbucher/install/include/c++/v1" 

但无济于事,它似乎没有任何区别.

but to no avail, it does not seem to make any difference.

然后,我尝试遵循bazel教程来创建自定义工具链.文本没有太大帮助,因为他们实际上是在编写一个交叉工具,而我想做的是调整现有的主机规则,而bazel似乎以某种方式撤消了我尝试调整其参数的所有尝试.

Then I tried to follow a bazel tutorial to create a custom toolchain. The text does not help much because they are actually writing a cross tool while what I am trying to do is to tweak the existing host rules and somehow bazel seems to undo every attempt I try to tweak its parameters.

我已经说到了当前在我的github存储库中的要点 https://github.com/HFTrader/BazelCustomToolchain

I have got to the point that is currently in my github repository https://github.com/HFTrader/BazelCustomToolchain

但是它无法编译,我什至无法弄清楚如何开始调试此消息.

However it does not compile and I cannot even figure out how to start debugging this message.

$ bazel build --crosstool_top=@hbclang//:toolchain tensorflow:libtensorflow.so ..................... ERROR: The crosstool_top you specified was resolved to '@hbclang//:toolchain', which does not contain a CROSSTOOL file. You can use a crosstool from the depot by specifying its label. INFO: Elapsed time: 2.216s 

我已将这些行添加到我的tensorflow/WORKSPACE

I have appended these lines to my tensorflow/WORKSPACE

new_local_repository( name="hbclang", path="/home/hbucher/BazelCustomToolchain", build_file = "/home/hbucher/BazelCustomToolchain/BUILD", ) 

我在bazel的Google网上论坛上问了这个问题,但他们将我重定向到了stackoverflow.在这一点上,我要放弃.

I have asked this question on bazel's google groups but they redirected me to stackoverflow. At this point I am about to give up.

有人尝试这样做吗?还是我在这里破土动工?

Have someone attempted to do this or I'm breaking ground here?

谢谢.

问题解答

已解决.并非以预期的方式,但对我有用.

Solved. Not in the intended way but it works for me.

export INSTALL_DIR="$HOME/install" export CC=$INSTALL_DIR/bin/clang export CXX=$INSTALL_DIR/bin/clang++ export CXXFLAGS="-stdlib=libc++ -L$INSTALL_DIR/lib" export LDFLAGS="-L$INSTALL_DIR/lib -lm -lrt" export LD_LIBRARY_PATH="/usr/lib:/lib/x86_64-linux-gnu/:$INSTALL_DIR/lib" git clone https://github.com/tensorflow/tensorflow.git tensorflow-github cd tensorflow-github mkdir build-tmp && cd build-tmp cmake ../tensorflow/contrib/cmake/ make -j4 

使用cmake轻松实现1-2-3

Easy as 1-2-3 with cmake

这篇关于使用自定义Clang + Libc ++(而不是stdlibc ++)编译Tensorflow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程技术网(www.editcode.net)!

腾讯云服务器

相关推荐

阿里云服务器
关注微信
^