Closed imnotkind closed 5 years ago
The DLL is built without exposing any symbols, so any symbol you want to have, you will have to add it yourself. Please check this reply
I myself wrote a FindTensorFlow.cmake file, which you can use with a find_package(TensorFlow REQUIRED) call in your cmake project . That shows a bit how to link all the libs and how to add the include dirs.
find_package(TensorFlow 1.11.0 REQUIRED)
target_include_directories(<your-target> ${TensorFlow_INCLUDE_DIRS})
target_link_libraries(<your-target> ${TensorFlow_LIBRARIES})
FindTensorFlow.cmake:
# Locates the TensorFlow v1.11.0 C++ shared library and include directories.
include(FindPackageHandleStandardArgs)
unset(TENSORFLOW_FOUND)
message(STATUS "TensorFlow_DIR is defined as ${TensorFlow_DIR}")
# Finding main TensorFlow library.
find_library(TensorFlow_LIBRARY
NAMES
tensorflow_cc
libtensorflow_cc.so.if
libtensorflow_cc.so
PATHS
${TensorFlow_DIR}/tensorflow/lib
)
# Finding TensorFlow framework library if available.
# Only needed in case the framework library is built together with the cc library.
find_library(TensorFlow_FW_LIBRARY
NAMES
tensorflow_framework
libtensorflow_framework.so
PATHS
${TensorFlow_DIR}/tensorflow/lib
)
# Finding TensorFlow main include directory.
find_path(TensorFlow_INCLUDE_DIR
NAMES
tensorflow
PATHS
${TensorFlow_DIR}/tensorflow/include
)
# Finding TensorFlow protobuf include directory.
# On Linux this is merged with the main include directory.
if (WIN32)
find_path(TensorFlow_INCLUDE_DIR_pb
NAMES
tensorflow
PATHS
${TensorFlow_DIR}/tensorflow/include_pb
)
endif()
# Finding Eigen include directory.
find_path(Eigen_INCLUDE_DIR_third_party
NAMES
third_party
PATHS
${TensorFlow_DIR}/Eigen/include
)
# Finding Abseil include directory.
find_path(ABSL_INCLUDE_DIR
NAMES
absl
PATHS
${TensorFlow_DIR}/absl/include
)
# Find Protobuf package.
option(protobuf_MODULE_COMPATIBLE BOOL ON)
find_package(Protobuf 3.6.0 REQUIRED NO_DEFAULT_PATH
PATHS
${TensorFlow_DIR}/protobuf/lib/cmake/protobuf/
${TensorFlow_DIR}/protobuf/lib64/cmake/protobuf/
${TensorFlow_DIR}/protobuf/cmake/
)
# Find Eigen3 package.
message(STATUS "Finding Eigen...")
set(ENV{EIGEN3_ROOT_DIR} "${TensorFlow_DIR}/Eigen/eigen_archive")
find_package(Eigen3 QUIET
PATHS
${TensorFlow_DIR}/Eigen/eigen_archive/cmake
)
if(NOT Eigen_FOUND)
include(${TensorFlow_DIR}/Eigen/eigen_archive/cmake/FindEigen3.cmake)
set(Eigen_INCLUDE_DIR ${EIGEN3_INCLUDE_DIR})
endif()
# set TensorFlow_FOUND
find_package_handle_standard_args(TensorFlow DEFAULT_MSG TensorFlow_INCLUDE_DIR TensorFlow_LIBRARY)
# Set external variables for usage in CMakeLists.txt
if(TENSORFLOW_FOUND)
set(TensorFlow_LIBRARIES
"${TensorFlow_LIBRARY}"
"${Protobuf_LIBRARIES}"
"Eigen3::Eigen"
)
# Add TensorFlow framework library if found.
if(TensorFlow_FW_LIBRARY)
list(APPEND TensorFlow_LIBRARIES "${TensorFlow_FW_LIBRARY}")
endif()
set(TensorFlow_INCLUDE_DIRS
"${TensorFlow_INCLUDE_DIR}"
"${Eigen_INCLUDE_DIR_third_party}"
"${ABSL_INCLUDE_DIR}"
"${Protobuf_INCLUDE_DIRS}"
)
if (WIN32)
list(APPEND TensorFlow_INCLUDE_DIRS "${TensorFlow_INCLUDE_DIR_pb}")
endif()
endif()
# Hide local variables from GUI.
mark_as_advanced(
Protobuf_LIBRARIES
TensorFlow_LIBRARY
TensorFlow_FW_LIBRARY
TensorFlow_INCLUDE_DIR
TensorFlow_INCLUDE_DIR_pb
Protobuf_INCLUDE_DIRS
Eigen_INCLUDE_DIR
Eigen_INCLUDE_DIR_third_party
ABSL_INCLUDE_DIR
)
The files used are copied with the commands below:
# Install tensorflow lib and includes to bin.
mkdir $TensorFlowBinDir\tensorflow\lib\ -ErrorAction SilentlyContinue
Copy-Item $TensorFlowSourceDir\bazel-bin\tensorflow\libtensorflow_cc.so $TensorFlowBinDir\tensorflow\lib\tensorflow_cc.dll -Force
Copy-Item $TensorFlowSourceDir\bazel-bin\tensorflow\libtensorflow_cc.so.if.lib $TensorFlowBinDir\tensorflow\lib\tensorflow_cc.lib -Force
Copy-Item $TensorFlowSourceDir\tensorflow\core $TensorFlowBinDir\tensorflow\include\tensorflow\core -Recurse -Container -Filter "*.h" -Force
Copy-Item $TensorFlowSourceDir\tensorflow\cc $TensorFlowBinDir\tensorflow\include\tensorflow\cc -Recurse -Container -Filter "*.h" -Force
Copy-Item $TensorFlowSourceDir\bazel-genfiles\tensorflow\core\ $TensorFlowBinDir\tensorflow\include_pb\tensorflow\core -Recurse -Container -Filter "*.h" -Force
Copy-Item $TensorFlowSourceDir\bazel-genfiles\tensorflow\cc $TensorFlowBinDir\tensorflow\include_pb\tensorflow\cc -Recurse -Container -Filter "*.h" -Force
# Absl includes.
Copy-Item $TensorFlowSourceDir\bazel-source\external\com_google_absl\absl $TensorFlowBinDir\absl\include\absl\ -Recurse -Container -Filter "*.h" -Force
# Eigen includes
Copy-Item $TensorFlowSourceDir\bazel-source\external\eigen_archive\ $TensorFlowBinDir\Eigen\eigen_archive -Recurse -Force
Copy-Item $TensorFlowSourceDir\third_party\eigen3 $TensorFlowBinDir\Eigen\include\third_party\eigen3\ -Recurse -Force
Sorry for not trying to build once again. I built it again with my symbols in tf_exported_symbols_msvc.lds
, and it worked! thanks :)
I'm not used to Cmake files, but I probably assume that the copied files from below are the required header and library files, and Cmake is used to generate a project that has those dependencies?
I get most of the things, but how did you install protobuf?
I just included source\bazel-source\external\protobuf_archive\src
, but it seems you have a different include path with me.
# Find Protobuf package.
option(protobuf_MODULE_COMPATIBLE BOOL ON)
find_package(Protobuf 3.6.0 REQUIRED NO_DEFAULT_PATH
PATHS
${TensorFlow_DIR}/protobuf/lib/cmake/protobuf/
${TensorFlow_DIR}/protobuf/lib64/cmake/protobuf/
${TensorFlow_DIR}/protobuf/cmake/
)
And what about this?
# Finding TensorFlow framework library if available.
# Only needed in case the framework library is built together with the cc library.
find_library(TensorFlow_FW_LIBRARY
NAMES
tensorflow_framework
libtensorflow_framework.so
PATHS
${TensorFlow_DIR}/tensorflow/lib
)
Is it ok for me to ignore this library, when libtensorflow_framework.so
was NOT in my bazel-bin
as output of bazel build //tensorflow:libtensorflow_cc.so
, or do I need to compile that library additionally?
Sorry for not trying to build once again. I built it again with my symbols in
tf_exported_symbols_msvc.lds
, and it worked! thanks :) I'm not used to Cmake files, but I probably assume that the copied files from below are the required header and library files, and Cmake is used to generate a project that has those dependencies? I get most of the things, but how did you install protobuf? I just includedsource\bazel-source\external\protobuf_archive\src
, but it seems you have a different include path with me.# Find Protobuf package. option(protobuf_MODULE_COMPATIBLE BOOL ON) find_package(Protobuf 3.6.0 REQUIRED NO_DEFAULT_PATH PATHS ${TensorFlow_DIR}/protobuf/lib/cmake/protobuf/ ${TensorFlow_DIR}/protobuf/lib64/cmake/protobuf/ ${TensorFlow_DIR}/protobuf/cmake/ )
Hi, I build my own protobuf CMake project and include the headers and library.
Second question: Indeed you do not need that TensorFlow framework library. We had some systems on which it was compiled additionally. If you don't have it and it works, then leave it out.
@Steroes Does it mean building protobuf using CMake is still needed?
well for my case, just including source\bazel-source\external\protobuf_archive\src
without the need of any .lib
files worked, at least for the c++ example, but I'm not sure if it's because I just ran a tutorial code.
@imnotkind Can you run the built binary without linking *.lib
files?
@Steroes Does it mean building protobuf using CMake is still needed?
I still need it, but I don't use the configuration from this repository. Not sure if it is still needed when the files are included that @imnotkind is referring to.
well, I think it's not needed if you include those files. thank you guys for your help, and for someone in need, I'm going to leave my extraction script. https://gist.github.com/imnotkind/6e41217ee8e6cf1373a883681d245029
Hello. I appreciate your work and I succeeded in building tensorflow 1.13.1 by your script. I just wanted to run an example on Visual Studio 2017, and I chose this one.
I included
to get rid of some third party related include errors. (protobuf, absl, eigen) I guess I achieved that goal, since I got rid of include errors.
and I only set
tensorflow_cc.lib
andtensorflow_cc.dll
as for any static/dynamic libraries.At the first try, I had some lack of symbols, and I used
dumpbin
to extract every symbol fromtensorflow_cc.dll
, and made my owntensorflow_cc.lib
. That got rid of some unresolved external symbol errors, but not all of them. The thing is, thistensorflow_cc.dll
we compiled by bazel just doesn't have enough functions. (Or that's what I think so) if you look at https://joe-antognini.github.io/machine-learning/windows-tf-project, (which is an example of using cmake to integrate tensorflow in windows, but cmake is broke for recent versions, I tried a lot.) he sets a tremendous amount of linker settingsand I'm highly convinced that our single
tensorflow_cc.dll
doesn't have all the functions in that amount of libs.I assume you guys are able to actually test and run the program with C++ api. Can you please tell me the details? What did you include? What static/dynamic libraries did you use? What is the code you used for testing? And last, what should I do to find my needed functions, which are
in this example code?