Tensorflow and Bazel c++ - c++

I'm trying to build tensorflow C++ from sources but no success. I followed different tutorials, but each time, there is a different error.
What I want to do is to create a library so I can use it with Qt. I followed this tutorial because it was exactly what I wanted:
https://tuatini.me/building-tensorflow-as-a-standalone-project/
(build on Ubuntu, not on raspberry)
It works fine until I have to use babel.
The tutorial says I have to run this command:
bazel build -c opt --verbose_failures //tensorflow:libtensorflow_cc.so
but it always fails with the error:
ERROR: /home/default/.cache/bazel/_bazel_default/045e1c5e9b482c7b029d706e128fc7e7/external/io_bazel_rules_closure/closure/stylesheets/closure_css_library.bzl:27:13: name 'set' is not defined
I have no idea where I'm supposed to define 'set' (I remove the .cache/bazel folder)
Other tutorials I followed gave me errors such as bazel needs to be > 0.4.3, found 0.13.1 as if it was strings instead of numbers...
Any idea on how to make it work?

Do you need to build Tensorflow 1.3.0? There's an old version of TF that can only be built with Bazel 0.5.1, according to the tutorial. You have Bazel 0.13.1, which doesn't support the keyword set in the build scripts. The latest version of TF is buildable with Bazel 0.13.1.
If you need to build 1.3.0, install an older version of Bazel (e.g. 0.5.4) from https://github.com/bazelbuild/bazel/tags?before=0.4.3.
To be exact, this error comes from one of the dependencies of TF, and not TF itself.

Related

How do you install Bazel in python2 environment?

How do you install Bazel in a python2 environment? The tensorflow website has an error posted on the such as this "Caution: Because of an bazel bug, we only support building the Android demo app within a Python 2 environment", (See related Bazel installation on windows">Bazel installation on Windows). How do you install Bazel in a python2 environment( to get apps working on Windows, using bazel)? The Bazel install in a python2 environment may be a workaround for the error shown earlier on the Tensorflow website, they do not seem to have any other workarounds known.
Download and install Python2 (e.g. from python.org: Python 2.7.15, 64-bit version[1])
Use the --python_path flag[2] to tell Bazel where's the Python interpreter.
For example if you installed Python2 under c:\python2, run Bazel like so:
c:\tensorflow> bazel build --python_path=c:/python2/python.exe //foo:bar
If you want Bazel to always use this flag in this workspace (c:\tensorflow), add the following line to c:\tensorflow\.bazelrc:
build --python_path=c:/python2/python.exe
(You may need to add this line every time you re-run the configure script.)
Update: here's more info about .bazelrc files[3], what they are, where they are, how to specify them.
[1] https://www.python.org/ftp/python/2.7.15/python-2.7.15.amd64.msi
[2] https://docs.bazel.build/versions/master/command-line-reference.html
[3] https://docs.bazel.build/versions/master/user-manual.html#bazelrc

Compile C/C++ files on target platform without node-gyp

I have some C/C++ code that I need to compile for target platforms (MacOS, Linux flavors, etc). However, it isn't for Node.js bindings, just some scripts written in C, so I don't absolutely need to use node-gyp to do this.
My question is - what is the best way to compile these C scripts if they are packaged in an NPM package. Should I just use the postinstall script to compile the C code? What is best practice here?
What is the best way to compile these C scripts if they are packaged in an NPM package
This tasks generally solved by crossplatform build systems like automake, cmake, qmake and so on.
Create an independent c++ package with configured build environment. Add to npm package checking that your program compiled from c++ is available. Show error message if it is not available and notice where to find it and mention in doc about how to compile and install.

C++ version of TensorFlow

I need to use the C++ API of TensorFlow. Therefore it seems necessary to build TensorFlow from sources, so I do this according to https://www.tensorflow.org/install/install_sources. I want to have the version with GPU support. I run the ./configure with mostly default options.
However when running
bazel build --config=opt --config=cuda
//tensorflow/tools/pip_package:build_pip_package
the following error occurs:
Cuda Configuration Error: cuDNN version detected from
/usr/lib/x86_64-linux-gnu/include/cudnn.h (7.0.3) does not match
TF_CUDNN_VERSION (6)
I had previously CuDNN 7 installled, but then installed cudnn 6 for use with tensorflow. What can I do?
Could you try disable CuDNN 7 from your environment varaities, and try to put the file in cudnn6 folder to the relative folder in your CUDA folder.
This works for me, hope it helps.

build syntaxnet with bazel: pywrap error

I am trying to build syntaxnet using bazel without root rights. I have downloaded bazel 0.2.2b and pulled the syntaxnet git repository as suggested on its website. I have managed to pass the new gcc for the bazel build and set my environment variables to include the local gcc as well as my local python version (2.7). I also added swig and jdk to PATH. Still, I get the following error when trying to run bazel test syntaxnet/... util/utf8/...:
INFO: Found 65 targets and 12 test targets...
ERROR: /home/davba/.cache/bazel/_bazel_debauscd/33ff1ccf943e8d1167bc44c81c9ea8f4/external/org_tensorflow/tensorflow/python/BUILD:1023:1: output 'external/org_tensorflow/tensorflow/python/pywrap_tensorflow.cc' was not created.
ERROR: /home/davba/.cache/bazel/_bazel_debauscd/33ff1ccf943e8d1167bc44c81c9ea8f4/external/org_tensorflow/tensorflow/python/BUILD:1023:1: output 'external/org_tensorflow/tensorflow/python/pywrap_tensorflow.py' was not created.
ERROR: /home/davba/.cache/bazel/_bazel_debauscd/33ff1ccf943e8d1167bc44c81c9ea8f4/external/org_tensorflow/tensorflow/python/BUILD:1023:1: not all outputs were created.
After that, none of the tests are run which means all twelve tests are skipped. Any ideas are highly appreciated.
Edit: I have realized that I used an old version of protobuf. Unfortunately, the problem remains even after updating.
Since it seems to be a python related problem and I had built python from source, I tried to use anaconda but ended up with the same error.
Some more information: I am using CentOS 6.5 and tried python 2.7.11.
I set the environment variables as follows and changed the CROSSTOOL file for building bazel accordingly:
CXX=/soft/csw/linux64/rel6/gccs-4.8.5/bin/c++
CC=/soft/csw/linux64/rel6/gccs-4.8.5/bin/gcc
LDFLAGS="-L/soft/csw/linux64/rel6/gccs-4.8.5/lib -L/soft/csw/linux64/rel6/gccs-4.8.5/lib64":"-L/home/davba/syntaxnet-utils/pcre/lib"
CXXFLAGS="-L/soft/csw/linux64/rel6/gccs-4.8.5/lib -L/soft/csw/linux64/rel6/gccs-4.8.5/lib64"
LD_LIBRARY_PATH=/soft/csw/linux64/rel6/gccs-4.8.5/lib:/soft/csw/linux64/rel6/gccs-4.8.5/lib64:/home/davba/AnacondaPython/lib:$LD_LIBRARY_PATH
SWIG_PATH=/home/davba/syntaxnet-utils/compiled-swig/bin
Thanks!
I tried running it on a different machine with CentOS 7.0, but wound up with the same error.
Finally, I had the opportunity to switch to an Ubuntu machine with sudo rights which enabled me to run the bazel installer and compile syntaxnet without a problem. This solves the problem in my case. For a "real" fix I think we have to wait for someone experiencing the same issue.

GL/glfw.h does not exist

I'm using Fedora 17 and compiling cocos2d-x. I've got an error at the compilation when I'm launching ./make-all-linux-project.sh.
G++ tells me that GL/glfw.h does not exist and then I yum install glew but it wasn't solved. So how can I solve this?
The package glew is actually the OpenGL Extension Wrangler. In this case your error is referring to a different package - GLFW. The problem with the build script you are trying to run is that it was made for deb-based systems, not rpm-based systems like Fedora. What's going to make this more difficult is that if you use YUM to download glfw and glfw-devel, they are not the version Cocos2d-x needs, so the build will fail. What you will need to do is first download a legacy version of glfw from Git Hub and build it from source.
git clone https://github.com/glfw/glfw-legacy.git
Once you build this package, you will need to modify the Cocos2d-x make file: $COCOS_ROOT/cocos2dx/proj.linux/cocos2dx.mk to include the legacy headers and also link to the legacy lib. The build should go smoothly after this, assuming all of your other dependencies are installed. You can refer to a blog post I put together for the detailed instructions: http://voidfuture.wordpress.com/2013/10/08/building-cocos2d-x-on-rhel-fedora-centos-linux/