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

No C++ symbols exported after built libtensorflow_cc with bazel on windows #23542

Closed
MoetaYuko opened this issue Nov 6, 2018 · 49 comments
Closed
Assignees
Labels
stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author stat:awaiting tensorflower Status - Awaiting response from tensorflower type:build/install Build and install issues

Comments

@MoetaYuko
Copy link
Contributor

Please make sure that this is a build/installation issue. As per our GitHub Policy, we only address code/doc bugs, performance issues, feature requests and build/installation issues on GitHub. tag:build_template

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):Windows 10
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary):source
  • TensorFlow version:v1.11.0
  • Python version:
  • Installed using virtualenv? pip? conda?:
  • Bazel version (if compiling from source):0.18.0 official build
  • GCC/Compiler version (if compiling from source):VC++ 2015.3 v14.00 (v140) MSVC
  • CUDA/cuDNN version:
  • GPU model and memory:

Describe the problem

Provide the exact sequence of commands / steps that you executed before running into the problem

Following the official documentation, I use bazel build -c opt //tensorflow:libtensorflow_cc.so to build tensorflow with c++ api on windows, since cmake is deprecated now.
Everything goes well, and libtensorflow_cc.so is generated in bazel out dir, which can be renamed to .dll, but I didn't find libtensorflow_cc.lib which should contain the exported symbols. Furthermore, I use dumpbin /exports libtensorflow_cc.so to view all the exported symbols (the output is attached in the next section), only TFE_* , TF_* and some other symbols are exported. Obviously no C++ symbols are exported.
I dig into the source code and found that there're extra parameters passed to the compiler which specifying a list of symbols to export on darwin and posix, but windows (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/BUILD#L480-L488). I'm not familiar to Microsoft toolchains, but can similar thing be passed to MSVC if necessary so that we can get a proper libtensorflow_cc with necessary symbols exported on windows?

Any other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

Output of dumpbin /exports libtensorflow_cc.so:

Microsoft (R) COFF/PE Dumper Version 14.15.26730.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file F:\libtensorflow_cc\execroot\org_tensorflow\bazel-out\x64_windows-opt\bin\tensorflow\libtensorflow_cc.so

File Type: DLL

  Section contains the following exports for libtensorflow_cc.so

    00000000 characteristics
    5BDF0174 time date stamp Sun Nov  4 22:25:56 2018
        0.00 version
           1 ordinal base
         233 number of functions
         233 number of names

    ordinal hint RVA      name

          1    0 02C79C50 ?DEVICE_CPU@tensorflow@@3QEBDEB
          2    1 02C79C58 ?DEVICE_GPU@tensorflow@@3QEBDEB
          3    2 02C79C60 ?DEVICE_SYCL@tensorflow@@3QEBDEB
          4    3 02618400 ?ThenBlasGemm@Stream@stream_executor@@QEAAAEAV12@W4Transpose@blas@2@0_K11MAEBV?$DeviceMemory@M@2@H2HMPEAV52@H@Z
          5    4 02618CA0 ?ThenBlasGemm@Stream@stream_executor@@QEAAAEAV12@W4Transpose@blas@2@0_K11MAEBV?$DeviceMemory@Uhalf@Eigen@@@2@H2HMPEAV52@H@Z
          6    5 02619540 ?ThenBlasGemm@Stream@stream_executor@@QEAAAEAV12@W4Transpose@blas@2@0_K11NAEBV?$DeviceMemory@N@2@H2HNPEAV52@H@Z
          7    6 02619DE0 ?ThenBlasGemm@Stream@stream_executor@@QEAAAEAV12@W4Transpose@blas@2@0_K11V?$complex@M@std@@AEBV?$DeviceMemory@V?$complex@M@std@@@2@H3H2PEAV72@H@Z
          8    7 0261A670 ?ThenBlasGemm@Stream@stream_executor@@QEAAAEAV12@W4Transpose@blas@2@0_K11V?$complex@N@std@@AEBV?$DeviceMemory@V?$complex@N@std@@@2@H3H2PEAV72@H@Z
          9    8 02C86690 ?kDatasetGraphKey@DatasetBase@tensorflow@@2QBDB
         10    9 02C866A0 ?kDatasetGraphOutputNodeKey@DatasetBase@tensorflow@@2QBDB
         11    A 001C8370 TFE_ContextAddFunction
         12    B 001C83C0 TFE_ContextAddFunctionDef
         13    C 001C8490 TFE_ContextAsyncClearError
         14    D 001C84A0 TFE_ContextAsyncWait
         15    E 001C84F0 TFE_ContextClearCaches
         16    F 001C8500 TFE_ContextDisableRunMetadata
         17   10 001C8510 TFE_ContextEnableRunMetadata
         18   11 001C8520 TFE_ContextEndStep
         19   12 001C8530 TFE_ContextExportRunMetadata
         20   13 001C8620 TFE_ContextGetDevicePlacementPolicy
         21   14 001C8630 TFE_ContextListDevices
         22   15 001C86A0 TFE_ContextOptionsSetAsync
         23   16 001C86B0 TFE_ContextOptionsSetConfig
         24   17 001C86C0 TFE_ContextOptionsSetDevicePlacementPolicy
         25   18 001C86D0 TFE_ContextSetAsyncForThread
         26   19 001C8720 TFE_ContextSetServerDef
         27   1A 001C87E0 TFE_ContextSetThreadLocalDevicePlacementPolicy
         28   1B 001C87F0 TFE_ContextStartStep
         29   1C 001C8800 TFE_DeleteContext
         30   1D 001C8830 TFE_DeleteContextOptions
         31   1E 001C8870 TFE_DeleteOp
         32   1F 001BFB40 TFE_DeleteTensorDebugInfo
         33   20 001C88A0 TFE_DeleteTensorHandle
         34   21 001C88F0 TFE_Execute
         35   22 001C8A50 TFE_NewContext
         36   23 001C8C40 TFE_NewContextOptions
         37   24 001C8C80 TFE_NewOp
         38   25 001C8E70 TFE_NewTensorHandle
         39   26 001C8F60 TFE_OpAddInput
         40   27 001C8F70 TFE_OpGetAttrType
         41   28 001C90E0 TFE_OpGetDevice
         42   29 001C9120 TFE_OpNameGetAttrType
         43   2A 001C91A0 TFE_OpSetAttrBool
         44   2B 001C9200 TFE_OpSetAttrBoolList
         45   2C 001C93B0 TFE_OpSetAttrFloat
         46   2D 001C9430 TFE_OpSetAttrFloatList
         47   2E 001C94B0 TFE_OpSetAttrFunction
         48   2F 001C9640 TFE_OpSetAttrFunctionList
         49   30 001C9850 TFE_OpSetAttrInt
         50   31 001C98D0 TFE_OpSetAttrIntList
         51   32 001C9950 TFE_OpSetAttrShape
         52   33 001C9C30 TFE_OpSetAttrShapeList
         53   34 001C9FF0 TFE_OpSetAttrString
         54   35 001CA070 TFE_OpSetAttrStringList
         55   36 001CA1E0 TFE_OpSetAttrType
         56   37 001CA230 TFE_OpSetAttrTypeList
         57   38 001CA2B0 TFE_OpSetDevice
         58   39 001CA300 TFE_OpSetXLACompilation
         59   3A 001BFB90 TFE_TensorDebugInfoOnDeviceDim
         60   3B 001BFBA0 TFE_TensorDebugInfoOnDeviceNumDims
         61   3C 001CA370 TFE_TensorHandleCopyToDevice
         62   3D 001CA420 TFE_TensorHandleDataType
         63   3E 001CA430 TFE_TensorHandleDeviceName
         64   3F 001CA510 TFE_TensorHandleDim
         65   40 001CA5C0 TFE_TensorHandleNumDims
         66   41 001CA670 TFE_TensorHandleResolve
         67   42 001BFBB0 TFE_TensorHandleTensorDebugInfo
         68   43 00372290 TF_AbortWhile
         69   44 003722A0 TF_AddControlInput
         70   45 003722B0 TF_AddGradients
         71   46 00372300 TF_AddGradientsWithPrefix
         72   47 00372BB0 TF_AddInput
         73   48 00372BC0 TF_AddInputList
         74   49 00372E50 TF_AllocateTensor
         75   4A 00372EC0 TF_ApiDefMapGet
         76   4B 00373070 TF_ApiDefMapPut
         77   4C 00373200 TF_CloseDeprecatedSession
         78   4D 00373200 TF_CloseSession
         79   4E 00373250 TF_ColocateWith
         80   4F 00373380 TF_DataTypeSize
         81   50 00373390 TF_DeleteApiDefMap
         82   51 003733C0 TF_DeleteBuffer
         83   52 00373400 TF_DeleteDeprecatedSession
         84   53 00373480 TF_DeleteDeviceList
         85   54 00366220 TF_DeleteFunction
         86   55 003734B0 TF_DeleteGraph
         87   56 00373520 TF_DeleteImportGraphDefOptions
         88   57 00373570 TF_DeleteImportGraphDefResults
         89   58 003735A0 TF_DeleteLibraryHandle
         90   59 003735D0 TF_DeletePRunHandle
         91   5A 003735E0 TF_DeleteSession
         92   5B 00373720 TF_DeleteSessionOptions
         93   5C 00373760 TF_DeleteStatus
         94   5D 003737B0 TF_DeleteTensor
         95   5E 00373820 TF_DeprecatedSessionListDevices
         96   5F 003738B0 TF_DeviceListCount
         97   60 003738E0 TF_DeviceListIncarnation
         98   61 00373A30 TF_DeviceListMemoryBytes
         99   62 00373B80 TF_DeviceListName
        100   63 00373CD0 TF_DeviceListType
        101   64 00373E20 TF_Dim
        102   65 00373E30 TF_ExtendGraph
        103   66 00373EF0 TF_FinishOperation
        104   67 00374250 TF_FinishWhile
        105   68 00366250 TF_FunctionGetAttrValueProto
        106   69 00366430 TF_FunctionImportFunctionDef
        107   6A 00366540 TF_FunctionName
        108   6B 00366570 TF_FunctionSetAttrValueProto
        109   6C 00366760 TF_FunctionToFunctionDef
        110   6D 00374890 TF_GetAllOpList
        111   6E 00374B60 TF_GetAllRegisteredKernels
        112   6F 00374C40 TF_GetBuffer
        113   70 001E4360 TF_GetCode
        114   71 00374C60 TF_GetOpList
        115   72 00374C80 TF_GetRegisteredKernelsForOp
        116   73 003667B0 TF_GraphCopyFunction
        117   74 003669D0 TF_GraphGetFunctions
        118   75 00374D90 TF_GraphGetOpDef
        119   76 00374F20 TF_GraphGetTensorNumDims
        120   77 00375050 TF_GraphGetTensorShape
        121   78 00375260 TF_GraphImportGraphDef
        122   79 003752A0 TF_GraphImportGraphDefWithResults
        123   7A 003753F0 TF_GraphImportGraphDefWithReturnOutputs
        124   7B 00375610 TF_GraphNextOperation
        125   7C 00366B80 TF_GraphNumFunctions
        126   7D 003756D0 TF_GraphOperationByName
        127   7E 003757F0 TF_GraphSetTensorShape
        128   7F 00366BF0 TF_GraphToFunction
        129   80 00375950 TF_GraphToGraphDef
        130   81 00375A10 TF_GraphVersions
        131   82 00375AD0 TF_ImportGraphDefOptionsAddControlDependency
        132   83 00375B00 TF_ImportGraphDefOptionsAddInputMapping
        133   84 00375CF0 TF_ImportGraphDefOptionsAddReturnOperation
        134   85 00375E70 TF_ImportGraphDefOptionsAddReturnOutput
        135   86 00375FC0 TF_ImportGraphDefOptionsNumReturnOperations
        136   87 00375FD0 TF_ImportGraphDefOptionsNumReturnOutputs
        137   88 00376000 TF_ImportGraphDefOptionsRemapControlDependency
        138   89 00376110 TF_ImportGraphDefOptionsSetPrefix
        139   8A 00376130 TF_ImportGraphDefOptionsSetUniquifyNames
        140   8B 00376140 TF_ImportGraphDefOptionsSetUniquifyPrefix
        141   8C 00376150 TF_ImportGraphDefResultsMissingUnusedInputMappings
        142   8D 00376170 TF_ImportGraphDefResultsReturnOperations
        143   8E 00376190 TF_ImportGraphDefResultsReturnOutputs
        144   8F 003761B0 TF_LoadLibrary
        145   90 00376260 TF_LoadSessionFromSavedModel
        146   91 00376890 TF_Message
        147   92 003768C0 TF_NewApiDefMap
        148   93 003769B0 TF_NewBuffer
        149   94 003769E0 TF_NewBufferFromString
        150   95 00376A40 TF_NewDeprecatedSession
        151   96 00376AD0 TF_NewGraph
        152   97 00376B00 TF_NewImportGraphDefOptions
        153   98 00376B70 TF_NewOperation
        154   99 00376BE0 TF_NewSession
        155   9A 00376D30 TF_NewSessionOptions
        156   9B 00376D60 TF_NewStatus
        157   9C 00376D90 TF_NewTensor
        158   9D 00377010 TF_NewWhile
        159   9E 00377430 TF_NumDims
        160   9F 00377440 TF_OperationDevice
        161   A0 00377460 TF_OperationGetAttrBool
        162   A1 00377500 TF_OperationGetAttrBoolList
        163   A2 003775F0 TF_OperationGetAttrFloat
        164   A3 003776A0 TF_OperationGetAttrFloatList
        165   A4 00377790 TF_OperationGetAttrInt
        166   A5 00377840 TF_OperationGetAttrIntList
        167   A6 00377930 TF_OperationGetAttrMetadata
        168   A7 00377F90 TF_OperationGetAttrShape
        169   A8 003780F0 TF_OperationGetAttrShapeList
        170   A9 003783B0 TF_OperationGetAttrString
        171   AA 00378490 TF_OperationGetAttrStringList
        172   AB 00378640 TF_OperationGetAttrTensor
        173   AC 00378730 TF_OperationGetAttrTensorList
        174   AD 00378910 TF_OperationGetAttrTensorShapeProto
        175   AE 003789B0 TF_OperationGetAttrTensorShapeProtoList
        176   AF 00378B60 TF_OperationGetAttrType
        177   B0 00378C00 TF_OperationGetAttrTypeList
        178   B1 00378CF0 TF_OperationGetAttrValueProto
        179   B2 00378D60 TF_OperationGetControlInputs
        180   B3 00378ED0 TF_OperationGetControlOutputs
        181   B4 00379040 TF_OperationInput
        182   B5 003790D0 TF_OperationInputListLength
        183   B6 00379290 TF_OperationInputType
        184   B7 003792A0 TF_OperationName
        185   B8 003792C0 TF_OperationNumControlInputs
        186   B9 003793F0 TF_OperationNumControlOutputs
        187   BA 00379520 TF_OperationNumInputs
        188   BB 00379530 TF_OperationNumOutputs
        189   BC 00379540 TF_OperationOpType
        190   BD 00379560 TF_OperationOutputConsumers
        191   BE 00379700 TF_OperationOutputListLength
        192   BF 003798C0 TF_OperationOutputNumConsumers
        193   C0 003799F0 TF_OperationOutputType
        194   C1 00379A00 TF_OperationToNodeDef
        195   C2 00379A60 TF_PRun
        196   C3 00379E00 TF_PRunSetup
        197   C4 0037A2E0 TF_Reset
        198   C5 0037A2F0 TF_Run
        199   C6 00373820 TF_SessionListDevices
        200   C7 0037A6A0 TF_SessionPRun
        201   C8 0037AB50 TF_SessionPRunSetup
        202   C9 0037B130 TF_SessionRun
        203   CA 0037B5F0 TF_SetAttrBool
        204   CB 0037B640 TF_SetAttrBoolList
        205   CC 0037B7E0 TF_SetAttrFloat
        206   CD 0037B820 TF_SetAttrFloatList
        207   CE 0037B880 TF_SetAttrFuncName
        208   CF 0037BA10 TF_SetAttrInt
        209   D0 0037BA50 TF_SetAttrIntList
        210   D1 0037BAB0 TF_SetAttrShape
        211   D2 0037BBC0 TF_SetAttrShapeList
        212   D3 0037BE20 TF_SetAttrString
        213   D4 0037BE80 TF_SetAttrStringList
        214   D5 0037C150 TF_SetAttrTensor
        215   D6 0037C230 TF_SetAttrTensorList
        216   D7 0037C590 TF_SetAttrTensorShapeProto
        217   D8 0037C720 TF_SetAttrTensorShapeProtoList
        218   D9 0037C9A0 TF_SetAttrType
        219   DA 0037C9E0 TF_SetAttrTypeList
        220   DB 0037CA40 TF_SetAttrValueProto
        221   DC 0037CC70 TF_SetConfig
        222   DD 0037CCD0 TF_SetDevice
        223   DE 0037CD10 TF_SetStatus
        224   DF 0037CDB0 TF_SetTarget
        225   E0 0037CDE0 TF_StringDecode
        226   E1 0037CF00 TF_StringEncode
        227   E2 0037CFE0 TF_StringEncodedSize
        228   E3 0037D000 TF_TensorByteSize
        229   E4 0037D010 TF_TensorData
        230   E5 0037D020 TF_TensorMaybeMove
        231   E6 0037D080 TF_TensorType
        232   E7 0037D090 TF_TryEvaluateConstant
        233   E8 0037D1F0 TF_Version

  Summary

      2D4000 .data
        1000 .gfids
      184000 .pdata
      B36000 .rdata
       53000 .reloc
     2949000 .text
        1000 .tls
       11000 _RDATA
@Harshini-Gadige Harshini-Gadige added type:build/install Build and install issues stat:awaiting tensorflower Status - Awaiting response from tensorflower labels Nov 9, 2018
@xianlopez
Copy link

xianlopez commented Nov 21, 2018

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): Yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Windows10
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow installed from (source or binary): source
  • TensorFlow version (use command below): r1.12
  • Python version: 3.5
  • Bazel version (if compiling from source): 0.15
  • GCC/Compiler version (if compiling from source): vc140
  • CUDA/cuDNN version: CUDA 10 / cuDNN 7.4.1.5
  • GPU model and memory: GTX 1080Ti / 11 GB
  • Exact command to reproduce:

Similar problem over here. I followed the official instructions to build Tensorflow in Windows using bazel (although I had to make a patch for eigen, as described here), and executed bazel build –config=opt –config=cuda //tensorflow:libtensorflow_cc.so. The compilation succeded.

However, the problems come when I want to include it in my own project (which I have in Visual Studio). I could not find any official documentation on how to do this; instead I had to search over many blogs or issues... Most of the explanations (if not all) refer to using the cmake build of Tensorflow, which now is not possible to do with the latest version.

Anyway, I found all the necessary headers around the bazel build. I had to include the following directories:

C:\development\tensorflow\bazel-tensorflow\external\eigen_archive
C:\development\tensorflow\bazel-tensorflow\external\com_google_absl
C:\development\tensorflow\bazel-tensorflow\external\protobuf_archive_src
C:\development\tensorflow\bazel-genfiles
C:\development\tensorflow\bazel-tensorflow

But the problem comes when linking...

When I execute dumpbin /exports libtensorflow_cc.so I get far more symbols than you (3061). To be able to link them, I had to build the .lib file from libtensorflow_cc.so. I did dumpbin /EXPORTS libtensorflow_cc.so > myfile.exports, I copied all the functions names and pasted them in a file called myfile.def (and added a line with the word EXPORTS at the beginning), and then did lib /def:myfile.def /out:tensorflow.lib /machine:x64. Then in Visual Studio I included tensorflow.lib.

However, when compiling my project, it is still requiring more symbols than those present in libtensorflow_cc.so. This is the output I get:

1>stdafx.cpp
1>BrainServer.cpp
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): warning C4005: 'COMPILER_MSVC': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): note: command-line arguments:  see previous definition of 'COMPILER_MSVC'
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): warning C4005: 'NOMINMAX': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): note: command-line arguments:  see previous definition of 'NOMINMAX'
1>BrainServer.cpp(62): warning C4101: 'm_logLevel': unreferenced local variable
1>BrainServerConfig.cpp
1>ClassificationRunner.cpp
1>c:\development\daview\brainserver\brainserver\ClassificationRunner.h(3): warning C4005: 'COMPILER_MSVC': macro redefinition
1>c:\development\daview\brainserver\brainserver\ClassificationRunner.h(3): note: command-line arguments:  see previous definition of 'COMPILER_MSVC'
1>c:\development\daview\brainserver\brainserver\ClassificationRunner.h(4): warning C4005: 'NOMINMAX': macro redefinition
1>c:\development\daview\brainserver\brainserver\ClassificationRunner.h(4): note: command-line arguments:  see previous definition of 'NOMINMAX'
1>Crop.cpp
1>SharedListsManager.cpp
1>ImageSaver.cpp
1>NetworkRunner.cpp
1>c:\development\daview\brainserver\brainserver\NetworkRunner.h(3): warning C4005: 'COMPILER_MSVC': macro redefinition
1>c:\development\daview\brainserver\brainserver\NetworkRunner.h(3): note: command-line arguments:  see previous definition of 'COMPILER_MSVC'
1>c:\development\daview\brainserver\brainserver\NetworkRunner.h(4): warning C4005: 'NOMINMAX': macro redefinition
1>c:\development\daview\brainserver\brainserver\NetworkRunner.h(4): note: command-line arguments:  see previous definition of 'NOMINMAX'
1>NetworkRunner.cpp(205): warning C4101: 'ex': unreferenced local variable
1>Query.cpp
1>Server.cpp
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): warning C4005: 'COMPILER_MSVC': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): note: command-line arguments:  see previous definition of 'COMPILER_MSVC'
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): warning C4005: 'NOMINMAX': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): note: command-line arguments:  see previous definition of 'NOMINMAX'
1>Session.cpp
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): warning C4005: 'COMPILER_MSVC': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): note: command-line arguments:  see previous definition of 'COMPILER_MSVC'
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): warning C4005: 'NOMINMAX': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): note: command-line arguments:  see previous definition of 'NOMINMAX'
1>TamperingRunner.cpp
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): warning C4005: 'COMPILER_MSVC': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(3): note: command-line arguments:  see previous definition of 'COMPILER_MSVC'
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): warning C4005: 'NOMINMAX': macro redefinition
1>c:\development\daview\brainserver\brainserver\TamperingRunner.h(4): note: command-line arguments:  see previous definition of 'NOMINMAX'
1>tinystr.cpp
1>tinyxml.cpp
1>tinyxmlerror.cpp
1>tinyxmlparser.cpp
1>BrainServer.obj : error LNK2001: unresolved external symbol "char const * __cdecl tensorflow::core::GetVarint32PtrFallback(char const *,char const *,unsigned int *)" (?GetVarint32PtrFallback@core@tensorflow@@YAPEBDPEBD0PEAI@Z)
1>BrainServer.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::Tensor::~Tensor(void)" (??1Tensor@tensorflow@@QEAA@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: void __cdecl google::protobuf::internal::LogFinisher::operator=(class google::protobuf::internal::LogMessage &)" (??4LogFinisher@internal@protobuf@google@@QEAAXAEAVLogMessage@123@@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: class google::protobuf::internal::LogMessage & __cdecl google::protobuf::internal::LogMessage::operator<<(char const *)" (??6LogMessage@internal@protobuf@google@@QEAAAEAV0123@PEBD@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl google::protobuf::internal::LogMessage::LogMessage(enum google::protobuf::LogLevel,char const *,int)" (??0LogMessage@internal@protobuf@google@@QEAA@W4LogLevel@23@PEBDH@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl google::protobuf::internal::LogMessage::~LogMessage(void)" (??1LogMessage@internal@protobuf@google@@QEAA@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::internal::LogMessageFatal::LogMessageFatal(char const *,int)" (??0LogMessageFatal@internal@tensorflow@@QEAA@PEBDH@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl tensorflow::internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@internal@tensorflow@@UEAA@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "private: void __cdecl tensorflow::TensorShapeRep::SlowCopyFrom(class tensorflow::TensorShapeRep const &)" (?SlowCopyFrom@TensorShapeRep@tensorflow@@AEAAXAEBV12@@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "private: void __cdecl tensorflow::TensorShapeRep::DestructorOutOfLine(void)" (?DestructorOutOfLine@TensorShapeRep@tensorflow@@AEAAXXZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::Tensor::Tensor(void)" (??0Tensor@tensorflow@@QEAA@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::Tensor::Tensor(enum tensorflow::DataType,class tensorflow::TensorShape const &)" (??0Tensor@tensorflow@@QEAA@W4DataType@1@AEBVTensorShape@1@@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::TensorShapeBase<class tensorflow::TensorShape>::TensorShapeBase<class tensorflow::TensorShape>(void)" (??0?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEAA@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::TensorShapeBase<class tensorflow::TensorShape>::TensorShapeBase<class tensorflow::TensorShape>(class absl::Span<__int64 const >)" (??0?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEAA@V?$Span@$$CB_J@absl@@@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::internal::CheckOpMessageBuilder::CheckOpMessageBuilder(char const *)" (??0CheckOpMessageBuilder@internal@tensorflow@@QEAA@PEBD@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::internal::CheckOpMessageBuilder::~CheckOpMessageBuilder(void)" (??1CheckOpMessageBuilder@internal@tensorflow@@QEAA@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: class std::basic_ostream<char,struct std::char_traits<char> > * __cdecl tensorflow::internal::CheckOpMessageBuilder::ForVar2(void)" (?ForVar2@CheckOpMessageBuilder@internal@tensorflow@@QEAAPEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl tensorflow::internal::CheckOpMessageBuilder::NewString(void)" (?NewString@CheckOpMessageBuilder@internal@tensorflow@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "private: void __cdecl tensorflow::Tensor::CheckIsAlignedAndSingleElement(void)const " (?CheckIsAlignedAndSingleElement@Tensor@tensorflow@@AEBAXXZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "private: static class absl::InlinedVector<__int64,4,class std::allocator<__int64> > __cdecl tensorflow::Tensor::ComputeFlatInnerDims(class absl::Span<__int64 const >,__int64)" (?ComputeFlatInnerDims@Tensor@tensorflow@@CA?AV?$InlinedVector@_J$03V?$allocator@_J@std@@@absl@@V?$Span@$$CB_J@4@_J@Z)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "public: class absl::InlinedVector<__int64,4,class std::allocator<__int64> > __cdecl tensorflow::TensorShapeBase<class tensorflow::TensorShape>::dim_sizes(void)const " (?dim_sizes@?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEBA?AV?$InlinedVector@_J$03V?$allocator@_J@std@@@absl@@XZ)
1>ClassificationRunner.obj : error LNK2001: unresolved external symbol "private: void __cdecl tensorflow::Tensor::CheckTypeAndIsAligned(enum tensorflow::DataType)const " (?CheckTypeAndIsAligned@Tensor@tensorflow@@AEBAXW4DataType@2@@Z)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::GraphDef::GraphDef(void)" (??0GraphDef@tensorflow@@QEAA@XZ)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl tensorflow::GraphDef::~GraphDef(void)" (??1GraphDef@tensorflow@@UEAA@XZ)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "public: __int64 __cdecl tensorflow::TensorShapeBase<class tensorflow::TensorShape>::dim_size(int)const " (?dim_size@?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEBA_JH@Z)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl tensorflow::ConfigProto::~ConfigProto(void)" (??1ConfigProto@tensorflow@@UEAA@XZ)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "class tensorflow::Status __cdecl tensorflow::ReadBinaryProto(class tensorflow::Env *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class google::protobuf::MessageLite *)" (?ReadBinaryProto@tensorflow@@YA?AVStatus@1@PEAVEnv@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAVMessageLite@protobuf@google@@@Z)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "public: static class tensorflow::Env * __cdecl tensorflow::Env::Default(void)" (?Default@Env@tensorflow@@SAPEAV12@XZ)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "class tensorflow::Status __cdecl tensorflow::ReadTextProto(class tensorflow::Env *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class google::protobuf::Message *)" (?ReadTextProto@tensorflow@@YA?AVStatus@1@PEAVEnv@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAVMessage@protobuf@google@@@Z)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "public: __cdecl tensorflow::SessionOptions::SessionOptions(void)" (??0SessionOptions@tensorflow@@QEAA@XZ)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "class tensorflow::Session * __cdecl tensorflow::NewSession(struct tensorflow::SessionOptions const &)" (?NewSession@tensorflow@@YAPEAVSession@1@AEBUSessionOptions@1@@Z)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "private: static class tensorflow::GPUOptions * __cdecl google::protobuf::Arena::CreateMaybeMessage<class tensorflow::GPUOptions>(class google::protobuf::Arena *)" (??$CreateMaybeMessage@VGPUOptions@tensorflow@@$$V@Arena@protobuf@google@@CAPEAVGPUOptions@tensorflow@@PEAV012@@Z)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "private: void __cdecl tensorflow::TensorShape::CheckDimsEqual(int)const " (?CheckDimsEqual@TensorShape@tensorflow@@AEBAXH@Z)
1>NetworkRunner.obj : error LNK2001: unresolved external symbol "private: void __cdecl tensorflow::TensorShape::CheckDimsAtLeast(int)const " (?CheckDimsAtLeast@TensorShape@tensorflow@@AEBAXH@Z)
1>C:\development\daview\BrainServer\x64\Release\BrainServer.exe : fatal error LNK1120: 34 unresolved externals
1>Done building project "BrainServer.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

In any case, it would be appreciated if there were some instructions on how to use the C++ API of Tensorflow in an independent project (not having to build it with bazel).

@StevenRoodhorst
Copy link

StevenRoodhorst commented Nov 23, 2018

Same problem here:
Compiled v1.11.0 from source on Windows 10 using Bazel 0.18.1 with Python 3.5.4.
Using bazel build --config=opt //tensorflow:libtensorflow_cc.so and renamed the so to .dll, and linked against the .lib.

I get the following linker errors when linking against it:

0>E:\VS\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"D:\dev\sources\quantib-dependencies\tensorflow\inference\source\build\Release\inference_cc.exe" /INCREMENTAL:NO /NOLOGO "D:\dev\sources\quantib-dependencies\tensorflow\source\bazel-bin\tensorflow\bin\libtensorflow_cc.lib" "D:\dev\sources\quantib-dependencies\tensorflow\build\deps\protobuf\bin\lib\libprotobuf.lib" kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /PDB:"D:/dev/sources/quantib-dependencies/tensorflow/inference/source/build/Release/inference_cc.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:/dev/sources/quantib-dependencies/tensorflow/inference/source/build/Release/inference_cc.lib" /MACHINE:X64  /machine:x64 inference_cc.dir\Release\inference_cc.obj
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::MetaGraphDef::MetaGraphDef(void)" (??0MetaGraphDef@tensorflow@@QEAA@XZ) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: virtual __cdecl tensorflow::MetaGraphDef::~MetaGraphDef(void)" (??1MetaGraphDef@tensorflow@@UEAA@XZ) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::internal::LogMessageFatal::LogMessageFatal(char const *,int)" (??0LogMessageFatal@internal@tensorflow@@QEAA@PEBDH@Z) referenced in function "private: void __cdecl tensorflow::Tensor::FillDimsAndValidateCompatibleShape<1>(class absl::Span<__int64 const >,class std::array<__int64,1> *)const " (??$FillDimsAndValidateCompatibleShape@$00@Tensor@tensorflow@@AEBAXV?$Span@$$CB_J@absl@@PEAV?$array@_J$00@std@@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: virtual __cdecl tensorflow::internal::LogMessageFatal::~LogMessageFatal(void)" (??1LogMessageFatal@internal@tensorflow@@UEAA@XZ) referenced in function "private: void __cdecl tensorflow::Tensor::FillDimsAndValidateCompatibleShape<1>(class absl::Span<__int64 const >,class std::array<__int64,1> *)const " (??$FillDimsAndValidateCompatibleShape@$00@Tensor@tensorflow@@AEBAXV?$Span@$$CB_J@absl@@PEAV?$array@_J$00@std@@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::internal::CheckOpMessageBuilder::CheckOpMessageBuilder(char const *)" (??0CheckOpMessageBuilder@internal@tensorflow@@QEAA@PEBD@Z) referenced in function "private: void __cdecl tensorflow::Tensor::FillDimsAndValidateCompatibleShape<1>(class absl::Span<__int64 const >,class std::array<__int64,1> *)const " (??$FillDimsAndValidateCompatibleShape@$00@Tensor@tensorflow@@AEBAXV?$Span@$$CB_J@absl@@PEAV?$array@_J$00@std@@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::internal::CheckOpMessageBuilder::~CheckOpMessageBuilder(void)" (??1CheckOpMessageBuilder@internal@tensorflow@@QEAA@XZ) referenced in function "private: void __cdecl tensorflow::Tensor::FillDimsAndValidateCompatibleShape<1>(class absl::Span<__int64 const >,class std::array<__int64,1> *)const " (??$FillDimsAndValidateCompatibleShape@$00@Tensor@tensorflow@@AEBAXV?$Span@$$CB_J@absl@@PEAV?$array@_J$00@std@@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: class std::basic_ostream<char,struct std::char_traits<char> > * __cdecl tensorflow::internal::CheckOpMessageBuilder::ForVar2(void)" (?ForVar2@CheckOpMessageBuilder@internal@tensorflow@@QEAAPEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@XZ) referenced in function "private: void __cdecl tensorflow::Tensor::FillDimsAndValidateCompatibleShape<1>(class absl::Span<__int64 const >,class std::array<__int64,1> *)const " (??$FillDimsAndValidateCompatibleShape@$00@Tensor@tensorflow@@AEBAXV?$Span@$$CB_J@absl@@PEAV?$array@_J$00@std@@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl tensorflow::internal::CheckOpMessageBuilder::NewString(void)" (?NewString@CheckOpMessageBuilder@internal@tensorflow@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "private: void __cdecl tensorflow::Tensor::FillDimsAndValidateCompatibleShape<1>(class absl::Span<__int64 const >,class std::array<__int64,1> *)const " (??$FillDimsAndValidateCompatibleShape@$00@Tensor@tensorflow@@AEBAXV?$Span@$$CB_J@absl@@PEAV?$array@_J$00@std@@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "char const * __cdecl tensorflow::core::GetVarint32PtrFallback(char const *,char const *,unsigned int *)" (?GetVarint32PtrFallback@core@tensorflow@@YAPEBDPEBD0PEAI@Z) referenced in function "char const * __cdecl tensorflow::core::GetVarint32Ptr(char const *,char const *,unsigned int *)" (?GetVarint32Ptr@core@tensorflow@@YAPEBDPEBD0PEAI@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tensorflow::Status::ToString(void)const " (?ToString@Status@tensorflow@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function "public: bool __cdecl tensorflow::Status::operator==(class tensorflow::Status const &)const " (??8Status@tensorflow@@QEBA_NAEBV01@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "private: void __cdecl tensorflow::Status::SlowCopyFrom(struct tensorflow::Status::State const *)" (?SlowCopyFrom@Status@tensorflow@@AEAAXPEBUState@12@@Z) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > * __cdecl tensorflow::TfCheckOpHelperOutOfLine(class tensorflow::Status const &,char const *)" (?TfCheckOpHelperOutOfLine@tensorflow@@YAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVStatus@1@PEBD@Z) referenced in function main
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "private: void __cdecl tensorflow::TensorShapeRep::DestructorOutOfLine(void)" (?DestructorOutOfLine@TensorShapeRep@tensorflow@@AEAAXXZ) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "private: void __cdecl tensorflow::TensorShapeRep::SlowCopyFrom(class tensorflow::TensorShapeRep const &)" (?SlowCopyFrom@TensorShapeRep@tensorflow@@AEAAXAEBV12@@Z) referenced in function "public: __cdecl std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor>::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor>(struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor> const &)" (??0?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VTensor@tensorflow@@@std@@QEAA@AEBU01@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::TensorShapeBase<class tensorflow::TensorShape>::TensorShapeBase<class tensorflow::TensorShape>(class absl::Span<__int64 const >)" (??0?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEAA@V?$Span@$$CB_J@absl@@@Z) referenced in function main
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::TensorShapeBase<class tensorflow::TensorShape>::TensorShapeBase<class tensorflow::TensorShape>(void)" (??0?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEAA@XZ) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::Tensor::Tensor(enum tensorflow::DataType,class tensorflow::TensorShape const &)" (??0Tensor@tensorflow@@QEAA@W4DataType@1@AEBVTensorShape@1@@Z) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::Tensor::~Tensor(void)" (??1Tensor@tensorflow@@QEAA@XZ) referenced in function "void __cdecl std::_Destroy_range1<class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor> >,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor> *>(struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor> *,struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor> *,struct std::_Wrap_alloc<class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class tensorflow::Tensor> > > &,struct std::integral_constant<bool,0>)" (??$_Destroy_range1@V?$allocator@U?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VTensor@tensorflow@@@std@@@std@@PEAU?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VTensor@tensorflow@@@2@@std@@YAXPEAU?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VTensor@tensorflow@@@0@0AEAU?$_Wrap_alloc@V?$allocator@U?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VTensor@tensorflow@@@std@@@std@@@0@U?$integral_constant@_N$0A@@0@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tensorflow::Tensor::DebugString(void)const " (?DebugString@Tensor@tensorflow@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function main
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "private: void __cdecl tensorflow::Tensor::CheckTypeAndIsAligned(enum tensorflow::DataType)const " (?CheckTypeAndIsAligned@Tensor@tensorflow@@AEBAXW4DataType@2@@Z) referenced in function "public: class Eigen::TensorMap<class Eigen::Tensor<float,1,1,__int64>,16,struct Eigen::MakePointer> __cdecl tensorflow::Tensor::shaped<float,1>(class absl::Span<__int64 const >)" (??$shaped@M$00@Tensor@tensorflow@@QEAA?AV?$TensorMap@V?$Tensor@M$00$00_J@Eigen@@$0BA@UMakePointer@2@@Eigen@@V?$Span@$$CB_J@absl@@@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "private: void __cdecl tensorflow::Tensor::CheckIsAlignedAndSingleElement(void)const " (?CheckIsAlignedAndSingleElement@Tensor@tensorflow@@AEBAXXZ) referenced in function "public: class Eigen::TensorMap<class Eigen::TensorFixedSize<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct Eigen::Sizes<>,1,__int64>,16,struct Eigen::MakePointer> __cdecl tensorflow::Tensor::scalar<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >(void)" (??$scalar@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Tensor@tensorflow@@QEAA?AV?$TensorMap@V?$TensorFixedSize@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@U?$Sizes@$S@Eigen@@$00_J@Eigen@@$0BA@UMakePointer@2@@Eigen@@XZ)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: static class tensorflow::Env * __cdecl tensorflow::Env::Default(void)" (?Default@Env@tensorflow@@SAPEAV12@XZ) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "class tensorflow::Status __cdecl tensorflow::ReadBinaryProto(class tensorflow::Env *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class google::protobuf::MessageLite *)" (?ReadBinaryProto@tensorflow@@YA?AVStatus@1@PEAVEnv@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAVMessageLite@protobuf@google@@@Z) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: virtual __cdecl tensorflow::ConfigProto::~ConfigProto(void)" (??1ConfigProto@tensorflow@@UEAA@XZ) referenced in function main
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "public: __cdecl tensorflow::SessionOptions::SessionOptions(void)" (??0SessionOptions@tensorflow@@QEAA@XZ) referenced in function main
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "class tensorflow::Status __cdecl tensorflow::NewSession(struct tensorflow::SessionOptions const &,class tensorflow::Session * *)" (?NewSession@tensorflow@@YA?AVStatus@1@AEBUSessionOptions@1@PEAPEAVSession@1@@Z) referenced in function main
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "class tensorflow::GraphDefDefaultTypeInternal tensorflow::_GraphDef_default_instance_" (?_GraphDef_default_instance_@tensorflow@@3VGraphDefDefaultTypeInternal@1@A) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>inference_cc.obj(0,0): Error LNK2019: unresolved external symbol "class tensorflow::SaverDefDefaultTypeInternal tensorflow::_SaverDef_default_instance_" (?_SaverDef_default_instance_@tensorflow@@3VSaverDefDefaultTypeInternal@1@A) referenced in function "class tensorflow::Status __cdecl LoadModel(class tensorflow::Session *,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?LoadModel@@YA?AVStatus@tensorflow@@PEAVSession@2@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@1@Z)
0>D:\dev\sources\quantib-dependencies\tensorflow\inference\source\build\Release\inference_cc.exe(0,0): Error LNK1120: 28 unresolved externals
0>------- Project finished: inference_cc. Succeeded: False. Errors: 29. Warnings: 0

Configuration used for ./configure:

set PYTHON_BIN_PATH=%SCRIPT_DIR%\venv\Scripts\python.exe
set PYTHON_LIB_PATH=%SCRIPT_DIR%\venv\lib\site-packages\

set TF_NEED_GCP=0
set TF_NEED_CUDA=0
set TF_NEED_AWS=0
set TF_NEED_JEMALLOC=0
set TF_NEED_GCP=0
set TF_NEED_HDFS=0
set TF_NEED_KAFKA=0
set TF_ENABLE_XLA=0
set TF_NEED_GDR=0
set TF_NEED_VERBS=0
set TF_NEED_NGRAPH=0
set TF_CUDA_CLANG=0
set TF_NEED_OPENCL_SYCL=0
set TF_NEED_MPI=0
set TF_DOWNLOAD_CLANG=0
set CC_OPT_FLAGS="/arch:AVX2"
set TF_SET_ANDROID_WORKSPACE=0
set TF_OVERRIDE_EIGEN_STRONG_INLINE=1

What I find weird is: I compiled it with the same settings on Ubuntu 16.04 with Python 3.6.7 and there the libtensorflow.so file is around 600MB in size, while on Windows only 60 Mb. So makes sense that we miss some symbols.

@StevenRoodhorst
Copy link

In addition, I solved my problem by using the approach here. I added the following symbols to the tf_exported_symbols_msvc.lds file for the inference_cc example.

LIBRARY tensorflow_cc
EXPORTS
    ??0MetaGraphDef@tensorflow@@QEAA@XZ
    ??1MetaGraphDef@tensorflow@@UEAA@XZ
    ??0LogMessageFatal@internal@tensorflow@@QEAA@PEBDH@Z
    ??1LogMessageFatal@internal@tensorflow@@UEAA@XZ
    ??0CheckOpMessageBuilder@internal@tensorflow@@QEAA@PEBD@Z
    ??1CheckOpMessageBuilder@internal@tensorflow@@QEAA@XZ
    ?ForVar2@CheckOpMessageBuilder@internal@tensorflow@@QEAAPEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@XZ
    ?NewString@CheckOpMessageBuilder@internal@tensorflow@@QEAAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
    ?GetVarint32PtrFallback@core@tensorflow@@YAPEBDPEBD0PEAI@Z
    ?ToString@Status@tensorflow@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
    ?SlowCopyFrom@Status@tensorflow@@AEAAXPEBUState@12@@Z
    ?_GraphDef_default_instance_@tensorflow@@3VGraphDefDefaultTypeInternal@1@A
    ?NewSession@tensorflow@@YA?AVStatus@1@AEBUSessionOptions@1@PEAPEAVSession@1@@Z
    ??0SessionOptions@tensorflow@@QEAA@XZ
    ??1ConfigProto@tensorflow@@UEAA@XZ
    ?ReadBinaryProto@tensorflow@@YA?AVStatus@1@PEAVEnv@1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAVMessageLite@protobuf@google@@@Z
    ?Default@Env@tensorflow@@SAPEAV12@XZ
    ?CheckIsAlignedAndSingleElement@Tensor@tensorflow@@AEBAXXZ
    ?_SaverDef_default_instance_@tensorflow@@3VSaverDefDefaultTypeInternal@1@A
    ?CheckTypeAndIsAligned@Tensor@tensorflow@@AEBAXW4DataType@2@@Z
    ??1Tensor@tensorflow@@QEAA@XZ
    ??0Tensor@tensorflow@@QEAA@W4DataType@1@AEBVTensorShape@1@@Z
    ??0?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEAA@XZ
    ??0?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEAA@V?$Span@$$CB_J@absl@@@Z
    ?DestructorOutOfLine@TensorShapeRep@tensorflow@@AEAAXXZ
    ?TfCheckOpHelperOutOfLine@tensorflow@@YAPEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVStatus@1@PEBD@Z
    ?DebugString@Tensor@tensorflow@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ
    ?SlowCopyFrom@TensorShapeRep@tensorflow@@AEAAXAEBV12@@Z

Now it links correctly! No renaming needed for the libtensorflow_cc.so file, only when adding it near the executable during runtime.

@HackersSpirit
Copy link

@Steroes : Can you please provide ex syntax of how to use create_def_file.py to generate symbols. I am getting error of file cannot be found.
In reference with the link you have posted.
I am trying to run a cpp program using tensorflow(1.8) build using bazel
And getting the linker error when i am trying to run the sample program using qt.
I just had a doubt that bazel generates many lib files when we build tensorflow:
In my case C:\tensorflow-r1.8\bazel-out\x64_windows-opt\bin\tensorflow\cc directory has lot of lib files relevant to cpp.
I tried to run a sample program linking all those relevant lib files but was getting linkage error.
I am asking this because when i build the sample program using bazel it gets build successfully without any error.
So i was thinking exporting the symbols to the tensorflow.lib files will make any sense specially in my case.

@terryzhao127
Copy link

terryzhao127 commented Dec 17, 2018

@Steroes Could you please kindly offer a short tutorial on how to solve the problem and configurations on linking?
I have asked a question on stackoverflow, and I hope people with similar problems can work together to solve it.

@StevenRoodhorst
Copy link

See my post. Let me know if it doesnt work.

@StevenRoodhorst
Copy link

@Steroes : Can you please provide ex syntax of how to use create_def_file.py to generate symbols. I am getting error of file cannot be found.
In reference with the link you have posted.
I am trying to run a cpp program using tensorflow(1.8) build using bazel
And getting the linker error when i am trying to run the sample program using qt.
I just had a doubt that bazel generates many lib files when we build tensorflow:
In my case C:\tensorflow-r1.8\bazel-out\x64_windows-opt\bin\tensorflow\cc directory has lot of lib files relevant to cpp.
I tried to run a sample program linking all those relevant lib files but was getting linkage error.
I am asking this because when i build the sample program using bazel it gets build successfully without any error.
So i was thinking exporting the symbols to the tensorflow.lib files will make any sense specially in my case.

I dont use the scripts, because they generate too many symbols which the linker cannot handle. I add them based on my linker errors. Just copy the signatures to the .lds file, see my link above to the contents of that file.

@kingstarcraft
Copy link

@Steroes could you please tell me how to get the tf_exported_symbols_msvc files?
I want to write complete tf_exported_symbols_msvc.lds, but I don't know how to get the name of the those function.

@StevenRoodhorst
Copy link

@Steroes could you please tell me how to get the tf_exported_symbols_msvc files?
I want to write complete tf_exported_symbols_msvc.lds, but I don't know how to get the name of the those function.

The file you can create manually, and put it in tensorflow\tensorflow\ directory. The content will be like

LIBRARY tensorflow_cc
EXPORTS
    ??0MetaGraphDef@tensorflow@@QEAA@XZ
    ??1MetaGraphDef@tensorflow@@UEAA@XZ
    ??0LogMessageFatal@internal@tensorflow@@QEAA@PEBDH@

This content you can get for your specific project by linking against the tensorflow lib (which will link against the dll). The linker errors that you will get from Visual Studio for example, will have the symbols in it. Look for the signatures like ??0MetaGraphDef@tensorflow@@QEAA@XZ. Copy and paste these in the tf_exported_symbols_msvc.lds file, and rerun the bazel build command. Then the dll will be relinked with the new symbols. Repeat until there are no more linker errors.

@kingstarcraft
Copy link

@Steroes Thanks a lot. but there is till bug when using
sess_options.config.mutable_gpu_options()->set_visible_device_list(gpu_d)
to config the session
In version 1.5, I fix the bug with add tf_proto_cc.lib before the tensorflow.lib to the Linker. so i guess some function about sess_options in tensorflow.lib was overried by the function in tf_proto_cc.lib.
but in version 1.12, I can't found tf_proto_cc.lib after build the tensorflow with bazel, so I want to try add the functions whitch in tf_proto_cc.lib to tf_exported_symbols_msvc.lds to fix the bug. But I can't get the functions name, beacuse there is no linker errors when build my project.

@StevenRoodhorst
Copy link

@kingstarcraft What error do you get then?

@ttdd11
Copy link

ttdd11 commented Mar 19, 2019

@kingstarcraft Did you solve this problem? Facing the same issue.

@rounakskm
Copy link

rounakskm commented May 17, 2019

Hello,
@Steroes I did what you mentioned. But the linker errors are not going.

I think it has to do with the fact that I am using TF 2.0 and the modifications in the BUILD file are different.
I added the missing symbols to the tf_exported_symbols_mscv.lds and ran the build again but that does not solve my linking errors. I get the same symbols as missing.

Some background on how I ran the build->
For TF 2.0 BUILD file I cannot use the git -diff file with the changes mentioned in (#22047 (comment)).
So I made the required changes manually (line 538 and 661 in this case), added the tf_exported_symbols.lds with my missing symbols and ran the bazel build //tensorflow:tensorflow_cc.

Line 558 of the tensorflow/BUILD file in r2.0 branch has the following:
add win_def_file for tensorflow_cc
win_def_file = select({
# We need this DEF file to properly export symbols on Windows
"//tensorflow:windows": ":tensorflow_filtered_def_file",
"//conditions:default": None,
}),

But I cant figure out the syntax of adding the tf_exported_symbols_mscv.lds
Please help

@StevenRoodhorst
Copy link

@rounakskm Is this still an issue? Please check or create issue on https://github.com/guikarist/tensorflow-windows-build-script otherwise.

@ZhuoranLyu
Copy link

@Steroes Thanks a lot. but there is till bug when using
sess_options.config.mutable_gpu_options()->set_visible_device_list(gpu_d)
to config the session
In version 1.5, I fix the bug with add tf_proto_cc.lib before the tensorflow.lib to the Linker. so i guess some function about sess_options in tensorflow.lib was overried by the function in tf_proto_cc.lib.
but in version 1.12, I can't found tf_proto_cc.lib after build the tensorflow with bazel, so I want to try add the functions whitch in tf_proto_cc.lib to tf_exported_symbols_msvc.lds to fix the bug. But I can't get the functions name, beacuse there is no linker errors when build my project.

Same error. Wondering how to solve the problem.

@ZhuoranLyu
Copy link

@ttdd11 Same issue. Did you fix this?

@ada2718
Copy link

ada2718 commented Aug 30, 2019

@ttdd11 Same issue. Did you fix this?

@ZhuoranLyu +1 .Did you fix this?

@ZhuoranLyu
Copy link

@ttdd11 Same issue. Did you fix this?

@ZhuoranLyu +1 .Did you fix this?

I figured it out. Just add the functions to tf_exported_symbols_msvc.lds.

@sitting-duck
Copy link

sitting-duck commented Oct 19, 2019

I was able to fix this for myself, building C++ on Windows, not using the tf_exported_symbols_msvc.lds method, but by using the TF_EXPORT method.

I made a README explaining my solution. The tutorial is step by step and starts at the very beginning, so you may have to scroll down past steps you have already done, like checking your hardware, installing Bazel etc.
Here is the url: https://ashley-tharp.medium.com/btw-if-you-enjoy-my-tutorial-i-always-appreciate-endorsements-on-my-linkedin-https-www-linkedin-a6d6fcba1e44

Probably you will want to scroll all the way down to step 7

It shows how to pass command to create .lib and .dll.

Then to test your .lib you should link into your c++ project,

Then it will show you how to identify and fix the missing symbols using the TF_EXPORT macro

I am actively working on making this tutorial better so feel free to respond to my comment here or email: ashley.tharp@gmail.com with feedback or if you are confused on a particular part. :)

@DBraun
Copy link

DBraun commented Oct 28, 2019

@sitting-duck Thank you for your guide. I've been trying your steps with the latest Tensorflow 2.0 code, Python 3.5.4, protobuf 3.8.0, Bazel 0.26.1, CUDA 10.1, cudnn 7.4 and Visual Studio 2017 Build Tools. I got to the last step where I see unresolved external symbols. I modified the source code of a few files with TF_EXPORT and #include "tensorflow/core/platform/macros.h" Then I redid the line for building tensorflow.lib. I noticed that the date modified of tensorflow.lib didn't change at this step but tensorflow.dll did change. And now the errors in my Visual Studio project that try to use the tensorflow.lib have a slightly different error:
unresolved external symbol __declspec(dllimport) public: __cdecl tensorflow::ops::Subtract ...

Based on looking at macros.h, If TF_COMPILE_LIBRARY had been set, then the macro would have been __declspec(dllexport) .... Would that have avoided the error? This was my reading on that https://stackoverflow.com/questions/8863193/what-does-declspecdllimport-really-mean
https://docs.microsoft.com/en-us/cpp/cpp/dllexport-dllimport?view=vs-2019

What are your Additional Include Directories and do they have the modified files with the TF_EXPORT and #include "tensorflow/core/platform/macros.h"?

Another issue is that some of the files I need to edit with TF_EXPORT are machine generated such as "\bazel-out\x64_windows-opt\bin\tensorflow\cc\ops\math_ops.h". I don't think it makes sense to edit these files.

@lattard
Copy link

lattard commented Oct 30, 2019

@sitting-duck Many thanks for the README file, it is indeed very useful, I followed all the steps and could build tf, generating the .dll and .lib function, however, similar to the people in this thread I have problems with unresolved external symbol. I made the modifications as indicated:

  • in the file session.h I added the line:
    #include "tensorflow/core/platform/macros.h"
    just after
    #ifndef TENSORFLOW_CORE_PUBLIC_SESSION_H_
    #define TENSORFLOW_CORE_PUBLIC_SESSION_H_

  • I added TF_EXPORT as follows:
    class Session {
    public:
    TF_EXPORT Session();

  • then I built the .lib again using:
    bazel build --config=cuda tensorflow:tensorflow.lib

However, after these steps I still have 2 unresolved external sumbol errors:

  1. Error LNK2019 unresolved external symbol "public: __cdecl tensorflow::SessionOptions::SessionOptions(void)" (??0SessionOptions@tensorflow@@qeaa@XZ) referenced in function xxxxx

  2. Error LNK2019 unresolved external symbol "class tensorflow::Session * __cdecl tensorflow::NewSession(struct tensorflow::SessionOptions const &)" (?NewSession@tensorflow@@YAPEAVSession@1@AEBUSessionOptions@1@@z) referenced in function xxxx

I tried building both a Release and Debug version, both failed with same errors.

Any hint on how can this be fixed ?

@Ruanlt
Copy link

Ruanlt commented Mar 31, 2020

@ttdd11 Same issue. Did you fix this?

@ZhuoranLyu +1 .Did you fix this?

I figured it out. Just add the functions to tf_exported_symbols_msvc.lds.

how did you konw the functions name?

@yonghenghuanmie
Copy link

Anyone try this again recently with the latest TensorFlow? I think we have to use Bazel 2.0.0

_TF_MAX_BAZEL_VERSION = '2.0.0'

but now I'm having trouble with bazel build --config=cuda tensorflow:tensorflow.dll
This is one of my environment variables.
BAZEL_VS: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
According to the error output I think it's using the 2017 tools. Maybe that's the issue?

ERROR: C:/users/-----/documents/github/tensorflow/tensorflow/core/kernels/BUILD:5427:1: C++ compilation of rule '//tensorflow/core/kernels:sparse_tensor_dense_matmul_op_gpu' failed (Exit 2)
c:\users\-----\_bazel_-----\dktb5wq4\execroot\org_tensorflow\external\eigen_archive\eigen\src/Core/util/XprHelper.h(114): warning: __host__ annotation is ignored on a function("no_assignment_operator") that is explicitly defaulted on its first declaration

I have the same problem,but after recompile,it passed.

@DBraun
Copy link

DBraun commented May 3, 2020

@07rafix Thank you for your instructions.

I'm using Visual Studio Community. I also happen to be building to a file named tensorflow.dll not tensorflow_cc.dll so this is my command:
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/link.exe" /nologo /DLL /SUBSYSTEM:CONSOLE -defaultlib:advapi32.lib -DEFAULTLIB:advapi32.lib -ignore:4221 /MACHINE:X64 @bazel-out/x64_windows-opt/bin/tensorflow/tensorflow.dll-2.params /OPT:ICF /OPT:REF /DEF:bazel-out/x64_windows-opt/bin/tensorflow/tensorflow_filtered_def_file.def /ignore:4070

I had to change the file permissions of libtensorflow.dll.ifso and tensorflow.dll

When I run, I get some warnings but no errors. I noticed that the date modified of tensorflow.dll increases, but tensorflow.lib stays the same. Should tensorflow.lib get updated? My other C++ project which has tensorflow.lib in Linker>Input is still failing to build because of missing symbols. I figure it's because tensorflow.lib isn't updating.

I shouldn't have to do bazel build --config=cuda tensorflow:tensorflow.lib again right?

@sitting-duck
Copy link

sitting-duck commented May 3, 2020 via email

@DBraun
Copy link

DBraun commented May 3, 2020

Cool but now I'm noticing that bazel build --config=cuda tensorflow:tensorflow.lib will replace tensorflow_filtered_def_file.def with a version without my added symbols. It also doesn't update or replace the tensorflow.lib unless I delete it beforehand.

There's probably a way of using lib.exe instead of link.exe to make tensorflow.lib without overwriting the definitions file. https://docs.microsoft.com/en-us/cpp/build/reference/running-lib?view=vs-2019

@DBraun
Copy link

DBraun commented May 3, 2020

Wow there's light at the end of this tunnel! I used lib.exe and got a tensorflow.lib

"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/lib.exe" /nologo /SUBSYSTEM:CONSOLE /MACHINE:X64 /DEF:bazel-out/x64_windows-opt/bin/tensorflow/tensorflow_filtered_def_file.def /out:bazel-out/x64_windows-opt/bin/tensorflow/tensorflow.lib /ignore:4070 -ignore:4221

My C++ program compiles and runs too.

Actually I spoke too soon.

When running link.exe it can't find these symbols which I've put in the def file

?CatPieces@internal@strings@tensorflow@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$initializer_list@Vstring_view@absl@@@5@@Z

??0Status@tensorflow@@QEAA@W4Code@error@1@Vstring_view@absl@@@Z

??0?$TensorShapeBase@VTensorShape@tensorflow@@@tensorflow@@QEAA@V?$Span@$$CB_J@absl@@@Z

?JoinPathImpl@internal@io@tensorflow@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$initializer_list@Vstring_view@absl@@@5@@Z

@07rafix
Copy link

07rafix commented May 4, 2020

@DBraun Every source file of Tensorflow is built to .lib (static libary) file.

For example in tensorflow/core/platform/strcat.h there is

namespace tensorflow {
  namespace strings {
    namespace internal {
         string CatPieces(std::initializer_list<StringPiece> pieces);
    } } }

where StringPiece is typedef for absl::string_view. And this function is your missing symbol. You can find this symbol by calling the below command inside the folder where binary files of tensorflow/core/platform are generated:

dumpbin /SYMBOLS strcat.lib

where strcat.lib should be located: bin\tensorflow\core\platform folder.

In output you can see:

150 00000000 SECT41 notype () External | ?CatPieces@internal@strings@tensorflow@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$initializer_list@Vstring_view@absl@@@5@@Z (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tensorflow::strings::internal::CatPieces(class std::initializer_list<class absl::string_view>))

How it is related to your problem?
The file strcat.lib should be listed in tensorflow_cc.dll-2.params (it contains all static library which are used by LINK.exe to generate DLL and import library):

/WHOLEARCHIVE:bazel-out/x64_windows-opt/bin/tensorflow/core/platform/annotation.lib
/WHOLEARCHIVE:bazel-out/x64_windows-opt/bin/tensorflow/core/platform/strcat.lib
/WHOLEARCHIVE:bazel-out/x64_windows-opt/bin/tensorflow/core/platform/numbers.lib

you have to pass this file when calling LINK.exe (This file is passed in the command which I attached in my first answer). So, passing both file .params and .def (which contains added missing symbols) all should work fine.

@DBraun
Copy link

DBraun commented May 4, 2020

Skip to update at bottom

Thank you @07rafix. In my case the file libstrcat.a has the symbols:
198 00000000 SECT41 notype () External | ?CatPieces@internal@strings@tensorflow@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$initializer_list@Vstring_view@lts_2020_02_25@absl@@@5@@Z (class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tensorflow::strings::internal::CatPieces(class std::initializer_list<class absl::lts_2020_02_25::string_view>))

I've noticed that the ending @lts_2020_02_25@absl@@@5@@Z is slightly different from what my C++ project says is missing:
Error LNK2001 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl tensorflow::strings::internal::CatPieces(class std::initializer_list<class absl::string_view>)" (?CatPieces@internal@strings@tensorflow@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$initializer_list@Vstring_view@absl@@@5@@Z)

Note @Vstring_view@lts_2020_02_25@absl@@@5@@Z vs. @Vstring_view@absl@@@5@@Z

So if I add the symbol that actually came out of the dumpbin command, the longer one with @lts_2020_02_25 in it, link.exe does build a new dll.

This doesn't create a new .lib file, so I did this:
"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/lib.exe" /nologo /SUBSYSTEM:CONSOLE /MACHINE:X64 /DEF:bazel-out/x64_windows-opt/bin/tensorflow/tensorflow_filtered_def_file.def /out:bazel-out/x64_windows-opt/bin/tensorflow/tensorflow.lib /ignore:4070 -ignore:4221

That created a new .lib, which I referenced in Linker>Input in my C++ project, but Visual Studio reports the same missing symbol, the one without @lts_2020_02_25 in it. If I do include that full symbol in tensorflow_filtered_def_file.def then link.exe fails.

In an alternative method, if I use the symbol from the dumpbin, link.exe works. Then I did
bazel build --config=cuda tensorflow:tensorflow.lib but that reset my customized tensorflow_filtered_def_file.def and my C++ project fails with all of its 22 missing symbols as opposed to just 4 that I mentioned earlier. Isn't your .def file getting reset too? At what moment do you get your .lib file? Thanks for your help.

Update: It appears to have been a problem with abseil-cpp. I switched to https://github.com/abseil/abseil-cpp/releases/tag/20200225 and got zero errors. I'll go ahead with testing my program now. Thank you!

@OnilDu39
Copy link

OnilDu39 commented Feb 4, 2021

So this issue is 3 years old and still open, proving that using tf in C++ on Windows is strictly impossible without manually intervening in the compilation process, with advanced knowledge.

I think this situation is far from satisfying and that this fact can be established :
Tensorflow CANNOT be used in C++ on Windows

@ringdk
Copy link

ringdk commented Feb 8, 2021

Agreed. Sadly this and a similar issue has caused us to move to PyTorch, which has been a much more pleasant experience in deploying ML on multiple platforms.

@kumariko
Copy link

@MoetaYuko We are checking to see if you still need help on this issue, as you are using an older version of tensorflow(1.x) which is officially considered as end of life. We recommend that you upgrade to 2.6 which is latest stable version of TF and let us know if the issue still persists in newer versions. Thanks!

@kumariko kumariko added the stat:awaiting response Status - Awaiting response from author label Oct 24, 2021
@MoetaYuko
Copy link
Contributor Author

@kumariko Thanks for your attention. It's been 3 years and I personally no longer need a fix. Dunno if other community members still need help.

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Oct 26, 2021
@kumariko
Copy link

@MoetaYuko Thanks for the update! Can anyone from the community please confirm , if this issue still persists? Thank you!

@kumariko kumariko added the stat:awaiting response Status - Awaiting response from author label Oct 26, 2021
@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler google-ml-butler bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label Nov 2, 2021
@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale This label marks the issue/pr stale - to be closed automatically if no activity stat:awaiting response Status - Awaiting response from author stat:awaiting tensorflower Status - Awaiting response from tensorflower type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests