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
Comments
System information
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 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:
But the problem comes when linking... When I execute However, when compiling my project, it is still requiring more symbols than those present in libtensorflow_cc.so. This is the output I get:
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). |
Same problem here: I get the following linker errors when linking against it:
Configuration used for ./configure:
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. |
In addition, I solved my problem by using the approach here. I added the following symbols to the
Now it links correctly! No renaming needed for the libtensorflow_cc.so file, only when adding it near the executable during runtime. |
@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. |
@Steroes Could you please kindly offer a short tutorial on how to solve the problem and configurations on linking? |
See my post. Let me know if it doesnt work. |
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. |
@Steroes could you please tell me how to get the tf_exported_symbols_msvc files? |
The file you can create manually, and put it in
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 |
@Steroes Thanks a lot. but there is till bug when using |
@kingstarcraft What error do you get then? |
@kingstarcraft Did you solve this problem? Facing the same issue. |
Hello, 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. Some background on how I ran the build-> Line 558 of the tensorflow/BUILD file in r2.0 branch has the following: But I cant figure out the syntax of adding the tf_exported_symbols_mscv.lds |
@rounakskm Is this still an issue? Please check or create issue on https://github.com/guikarist/tensorflow-windows-build-script otherwise. |
Same error. Wondering how to solve the problem. |
@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. |
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. 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. :) |
@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 Based on looking at macros.h, If What are your Additional Include Directories and do they have the modified files with the 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. |
@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:
However, after these steps I still have 2 unresolved external sumbol errors:
I tried building both a Release and Debug version, both failed with same errors. Any hint on how can this be fixed ? |
how did you konw the functions name? |
I have the same problem,but after recompile,it passed. |
@07rafix Thank you for your instructions. I'm using Visual Studio Community. I also happen to be building to a file named I had to change the file permissions of 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 |
I shouldn't have to do bazel build --config=cuda
tensorflow:tensorflow.lib again
right?
I believe you do have to build the lib again, this has been my experience.
…On Sun, May 3, 2020 at 12:34 PM David ***@***.***> wrote:
@07rafix <https://github.com/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?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#23542 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJ23ZVXCJ7JY4GZFZA7QCDRPWTKDANCNFSM4GB6Y42Q>
.
|
Cool but now I'm noticing that 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 |
Wow there's light at the end of this tunnel! I used lib.exe and got a tensorflow.lib
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
|
@DBraun Every source file of Tensorflow is built to .lib (static libary) file. For example in tensorflow/core/platform/strcat.h there is
where
where strcat.lib should be located: In output you can see:
How it is related to your problem?
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. |
Skip to update at bottom Thank you @07rafix. In my case the file I've noticed that the ending Note So if I add the symbol that actually came out of the dumpbin command, the longer one with This doesn't create a new .lib file, so I did this: 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 In an alternative method, if I use the symbol from the dumpbin, link.exe works. Then I did 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! |
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 : |
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. |
@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 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. |
@MoetaYuko Thanks for the update! Can anyone from the community please confirm , if this issue still persists? Thank you! |
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. |
Closing as stale. Please reopen if you'd like to work on this further. |
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
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 findlibtensorflow_cc.lib
which should contain the exported symbols. Furthermore, I usedumpbin /exports libtensorflow_cc.so
to view all the exported symbols (the output is attached in the next section), onlyTFE_*
,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
:The text was updated successfully, but these errors were encountered: