Nagamani Nagaraj
Nagamani Nagaraj

Reputation: 31

Error building tensorflow C++ shared library on windows

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!

Upvotes: 2

Views: 3984

Answers (2)

Yu Bao
Yu Bao

Reputation: 1

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.

Upvotes: 0

Sohaib Anwaar
Sohaib Anwaar

Reputation: 1547

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.

Upvotes: 1

Related Questions