2

My CMakeLists.txt includes the following lines:

execute_process(COMMAND "python" "-c" "import tensorflow as tf; print tf.sysconfig.get_lib()" OUTPUT_VARIABLE TF_LIB_DIR)

find_library(TF_LIB 
    NAMES tensorflow_framework 
    PATHS ${TF_LIB_DIR}
    NO_DEFAULT_PATH)

Unfortunately - the tensorflow library is not found. This is confirmed by doing: message(STATUS ${TF_LIB}) which prints out TF_LIB-NOTFOUND.

TF_LIB_DIR is set to /home/ubuntu/.local/lib/python2.7/site-packages/tensorflow by the execute_process call.

The contents of this directory is aux-bin contrib core examples include __init__.py __init__.pyc libtensorflow_framework.so python tools

What am I doing wrong?

Owen
  • 919
  • 5
  • 11
  • 1
    As you guess in your answer, your problem is a trailing newline at the end of the path. Referenced question describes how to strip it. – Tsyvarev Apr 10 '18 at 17:18

1 Answers1

2

I replaced the execute_process call with:

execute_process(COMMAND "python" "-c" "import tensorflow as tf; import sys; sys.stdout.write(tf.sysconfig.get_lib() + '/')" OUTPUT_VARIABLE TF_LIB_DIR)

I believe the problem was either the lack of path separator or the trailing newline that was written into OUTPUT_VARIABLE due to the python print statement appending a newline.

Owen
  • 919
  • 5
  • 11
  • Seems a bit shorter: execute_process(COMMAND "python" "-c" "import tensorflow as tf; print(tf.sysconfig.get_include())" OUTPUT_VARIABLE TF_INC) include_directories(${TF_INC}) – Matias Haeussler Aug 01 '19 at 19:30