2
votes

I am trying to build tensorflow as a standalone project and have been following this tutorial

http://www.stefanseibert.com/2017/10/tensorflow-as-dll-into-your-windows-c-project-with-gpu-support-and-cmake-v1-3/

but alternatively with cpu support

My environment setup versions

protobuf 3.6.1
tensorflow 1.10.0
tf.GIT_VERSION = b'v1.10.0-rc1-19-g656e7a2b34'

Here are the steps I used to generate the shared lib

  1. Acquired source code from https://github.com/tensorflow/tensorflow.git

  2. Have installed the dependencies since I do not use the python bindings, there is no need for SWIG, so I installed Git (version 2.15.1.windows.2) and cmake 3.11.1

  3. I used the 64bit tools from Visual Studio 2015 since VS2015 is necessary to build the DLL. I should be able to open the “VS2015 x64 Native Tools Command Prompt”. This is needed so VS uses the 64 bit toolset.

  4. Navigated in the commandline to the “tensorflow/contrib/cmake” subfolder of the source code and create a directory with “mkdir build”. Afterwards navigate to the fresh build folder with “cd build”.

  5. Create a build solution: cmake .. -A x64 -DCMAKE_BUILD_TYPE=RelWithDebInfo -Dtensorflow_BUILD_CC_EXAMPLE=OFF -Dtensorflow_ENABLE_GRPC_SUPPORT=OFF -Dtensorflow_BUILD_CC_TESTS=OFF -Dtensorflow_BUILD_PYTHON_TESTS=OFF -Dtensorflow_ENABLE_GPU=OFF -Dtensorflow_WIN_CPU_SIMD_OPTIONS=/arch:AVX -Dtensorflow_BUILD_SHARED_LIB=ON

  6. Everything went fine till this. To build the tensorflow.dll, I issued the following command: MSBuild /p:Configuration=RelWithDebInfo tensorflow.vcxproj

  7. This throws an error: D:\work\tensorflow\tensorflow/core/lib/core/stringpiece.h(34): fatal error C1083: Cannot open include file: 'absl/strings/string_view.h': No such file or directory ( compiling source file D:\work\tensorflow\tensorflow\core\lib\core\coding.cc) [D:\work\tensorflow\tensorflow\contrib\cmake\build\tf_core_lib.vcxproj].

  8. I fixed the above error with this: https://github.com/tensorflow/tensorflow/issues/22007#issuecomment-424553600.

  9. Doing the above I ended up with this error: path.obj : error LNK2019: unresolved external symbol "void __cdecl absl::base_internal::ThrowStdOutOfRange(char const *)" (?ThrowStdOutOfRange@base_internal@absl@@YA XPEBD@Z) referenced in function "class std::basic_string,class std::allocator > __cdecl tensorflow::io::internal::JoinPathIm

I am not able to proceed further. Any workaround for this? Thanks!

2
IIRC, string_view is a C++17 feature. Make sure you are running Visual Studio 2015 Update 3 or possibly even the latest version of VS2017. - James Poag
@JamesPoag std::string_view is a C++17 feature, but what the compiler is complaining about is that it cannot find the headers, and the link the library, for Abseil (which polyfills the feature for previous standards). - jdehesa
The TensorFlow team is dropping support for CMake building. According to the release notes, this was officially done in v1.11.0, but it was first announced in v1.10.0, I am not sure if just as a warning or because they actually started there... I do not know how to solve your issue, but I have been able to build a TF dll (actually a custom wrapper dll including TF) with Bazel on Windows, in case you want to consider that path. - jdehesa
Thanks @jdehesa Do you have the steps to create TF dll with Bazel on windows? - Nagamani Nagaraj
@NagamaniNagaraj More or less... I created a simplified wrapper because I'm not sure how to collect all the headers for a hypotetical tensorflow.dll (and anyway it would be too many and my wrapper has two). Mostly you follow the setup from Build from source on Windows, but instead of building //tensorflow/tools/pip_package:build_pip_package I added my own target that depends on //tensorflow/core:tensorflow marked with linkshared. - jdehesa

2 Answers

1
votes

lnk2019 error occurs when your directly you are using in your source code are not linked properly. Please add additional dependencies to your project.

  • Going to project properties
  • select C/C++ option
  • Add aditional dependencies
  • Go to Linker Option Below C/C++
  • Add additional Dependencies here.

It might be help full for you from getting out to LNK2019 problem

view this to understand LNK2019 error.

0
votes

I met same issue, I think tensorflow new version doesn't support CMake, but we can solve the issues. 1. Seems the absl version in project folder is out dated, so I cloned the latest version of abseil-cpp from: https://github.com/abseil/abseil-cpp 2. Use cmake to build the abseil-cpp, it will be fast. 3. Add lib path to tensorflow dependency, the needed one will be D:\git\abseil-cpp\abseil-cpp\build\absl\base\Release\absl_absl_throw_delegate.lib 4. If you meet other linking error, you can find the function name in absl sources and find the library contain it. Hope this can help you and people who may met this issue in future.