Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: FindTensorflow.cmake not working on MacOS #39

Open
MiguelAlgaba opened this issue Apr 19, 2019 · 8 comments
Open

CMake: FindTensorflow.cmake not working on MacOS #39

MiguelAlgaba opened this issue Apr 19, 2019 · 8 comments
Labels
contribution welcome something I haven't figured out yet what the best solution is. currently not supported This is outside the scope of this project. MacOS This issue is related to MacOS

Comments

@MiguelAlgaba
Copy link

I was trying to compile some of the examples requiring the Tensorflow C-API, however so far I'm unable to get FindTensorflow.cmake to find the version of Tensorflow I installed from source

I'm using macOS High Sierra v10.13.6
I installed Tensorflow using the following commands:

TENSORFLOW_SOURCE_DIR=tensorflow
cd ${TENSORFLOW_SOURCE_DIR} (latest master)
./configure (defaults settings on OSX)
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package (cpu-only build)
./bazel-bin/tensorflow/tools/pip_package/build_pip_package --nightly_flag /tmp/tensorflow_pkg
pip install --ignore-installed wrapt /tmp/tensorflow_pkg/tf_nightly-1.13.1-cp36-cp36m-macosx_10_13_x86_64.whl

cd ..
export TENSORFLOW_BUILD_DIR=tensorflow-build
mkdir ${TENSORFLOW_BUILD_DIR}
cp ${TENSORFLOW_SOURCE_DIR}/bazel-bin/tensorflow/*.so ${TENSORFLOW_BUILD_DIR}/
user@host $ cp ${TENSORFLOW_SOURCE_DIR}/bazel-genfiles/tensorflow/cc/ops/*.h ${TENSORFLOW_BUILD_DIR}/includes/tensorflow/cc/ops/
Then I tried example inside tensorflow-cmake/inference/cc

cmake .

And I get the following output

CMake Warning at /Users/miguel/Development/tensorflow-cmake/cmake/modules/FindTensorFlow.cmake:44 (message):
  This FindTensorflow.cmake is not tested on APPLE

  Please report if this works

  https://github.com/PatWie/tensorflow-cmake
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)


-- Detecting TensorFlow using python3 (use -DPYTHON_EXECUTABLE=... otherwise)
-- Detecting TensorFlow info - done
CMake Error at /Users/miguel/Development/tensorflow-cmake/cmake/modules/FindTensorFlow.cmake:166 (message):
  Your installed TensorFlow version 1.13 is not supported

  We tested against 1.9;1.9.0;1.10;1.10.0;1.11;1.11.0;1.12;1.12.0
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Users/miguel/Development/tensorflow-cmake/inference/cc/CMakeFiles/CMakeOutput.log".

Am I missing something?

Thanks a lot in advance!

@PatWie
Copy link
Owner

PatWie commented Apr 19, 2019

Is there really TensorFlow version "1.13"? I thought there is only "1.13.1". You might want to change the line

"1.9" "1.9.0" "1.10" "1.10.0" "1.11" "1.11.0" "1.12" "1.12.0")

and add your version. As soon as I have the CI for building the ops under 1.13.1 I will add it here to the repository. However, there are so many things which have been changed.

I do not have any way to test this under any Apple-Device. Would be nice to make it work under MacOS.

@MiguelAlgaba
Copy link
Author

Hi @PatWie thanks for your quick reply.

Adding 1.13 to the list of supported Tensorflow versions as you suggested and manually specifying the paths to the Tensorflow source and libraries I managed to get CMake to generate the makefile for the inference/cc example

Screen Shot 2019-04-22 at 18 17 10

Screen Shot 2019-04-22 at 18 21 48

However when I trying to build the example it says it cannot find <tensorflow/core/protobuf/meta_graph.pb.h>. Any ideas?

[ 50%] Building CXX object CMakeFiles/inference_cc.dir/inference_cc.cc.o
/Users/miguel/Development/tensorflow-cmake/inference/cc/inference_cc.cc:2:10: fatal error: 'tensorflow/core/protobuf/meta_graph.pb.h' file not found
#include <tensorflow/core/protobuf/meta_graph.pb.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/inference_cc.dir/inference_cc.cc.o] Error 1
make[1]: *** [CMakeFiles/inference_cc.dir/all] Error 2
make: *** [all] Error 2

Thanks in advance!

@MiguelAlgaba
Copy link
Author

Copying all the content of tensorflow/bazel-genfiles/tensorflow to tensorflow-build/includes manages to find tensorflow/core/protobuf/meta_graph.pb.h although it fails to build too

Scanning dependencies of target inference_cc
[ 50%] Building CXX object CMakeFiles/inference_cc.dir/inference_cc.cc.o
In file included from /Users/miguel/Development/tensorflow-cmake/inference/cc/inference_cc.cc:2:
/Users/miguel/Development/tensorflow-build/includes/tensorflow/core/protobuf/meta_graph.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
#include <google/protobuf/port_def.inc>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/inference_cc.dir/inference_cc.cc.o] Error 1
make[1]: *** [CMakeFiles/inference_cc.dir/all] Error 2
make: *** [all] Error 2

@PatWie
Copy link
Owner

PatWie commented Apr 24, 2019

This is strange as bazel downloads all dependencies including Google protobuf. Installing the protobuf by hand is a bad idea as version missmatchs can add additional issues.

Can you confirm there is no such file "port_def.inc". Which tensor flow version do you issue. It can be that they broke TF again:

tensorflow/tensorflow#27697

@MiguelAlgaba
Copy link
Author

Hi @PatWie yes I was using a more recent Tensorflow version from commit f90532431c3785166cff35ff427b652fe460f60b, so seems like the "port_def.inc" issue is related to the tensorflow/tensorflow#27697 issue you posted indeed.

I decided to use stable release v1.13.1 and compiling that version from source almost works as you can see here. Now the remaining error seems to be a linking issue

Screen Shot 2019-04-25 at 11 52 20

@MiguelAlgaba
Copy link
Author

MiguelAlgaba commented Apr 25, 2019

For reference this is how the paths look when calling cmake. They are automatically found when exporting the paths to TENSORFLOW_BUILD_DIR and TENSORFLOW_SOURCE_DIR

Screen Shot 2019-04-25 at 11 53 50

@MiguelAlgaba
Copy link
Author

Locally removing the unknown options --allow-multiple-definition -Wl,--whole-archive ${TensorFlow_LIBRARY} -Wl,--no-whole-archive I get undefined symbols

Screen Shot 2019-04-25 at 12 07 43

macos_undefined_symbols.txt

@PatWie
Copy link
Owner

PatWie commented Apr 25, 2019

These flags are important indeed (for g++). MacOS uses llvm. Not sure if an equivalent exists:(https://stackoverflow.com/a/17445806/7443104)

@PatWie PatWie added contribution welcome something I haven't figured out yet what the best solution is. MacOS This issue is related to MacOS currently not supported This is outside the scope of this project. labels Jun 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome something I haven't figured out yet what the best solution is. currently not supported This is outside the scope of this project. MacOS This issue is related to MacOS
Projects
None yet
Development

No branches or pull requests

2 participants