-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
How to build and use onnxruntime static lib on windows? #1472
Comments
there isn't a single onnxruntime static lib. unit tests are static linked against these libs so you can look at onnxruntime_unittests.cmake as example |
@jywu-msft Nice, thanks so much, Let me have a try. |
@smilexin did it work for you? if so, please close this issue. |
@faxu I'll try it this week and feedback quickly, thanks~ |
@jywu-msft I had spend some time but had't figure out which static libs were really needed to do inference. In the onnxruntime_unittests.cmake, if we can refer the part of enable onnxruntime_BUILD_SHARED_LIB code block? It's still not very clear about the dependency of test code and the source code, If we can select out the only infer part source code denpendencies? Thanks so much for your kindly help~ |
@jywu-msft One more question: What are the correspondent .h file dependencies of each static lib? I tried to use all the built static lib and the related .h file in my sight, but it always have unresolved external symbol errors as followings, thanks for having a look: |
shared lib is the preferred/recommended approach instead of static lib. another approach might be for you to do a build.bat --update (i.e. build without shared lib) to let cmake generate the VS project files. |
@jywu-msft Thanks for your kindly reply in a very detailed, it help me a lot. As you assum, i'am new to cmake, and we want to use onnxruntime in our sdk, which should use static link. I'll follow you guide to have a try, thanks 🙃 |
@jywu-msft thanks for you guide, i had successfully figured out the needed static libs and .h. When I load them in my project, there exist a another problem, the "RuntimeLibrary" didn't match, the error massage is as following: onnxruntime_session.lib(onnxruntime_c_api.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in ... So how can we change onnxruntime the default Runtime Library from /MD to /MT ? where can we change it? I try to set in VS ide, but some third party lib such as libprotobuf error occurs, as following: |
https://github.com/microsoft/onnxruntime/pull/757/commits I got it, use flag when build: --enable_msvc_static_runtime, can refer to CMakeLists.txt: onnxruntime_MSVC_STATIC_RUNTIME logic |
@smilexin what's wrong with onnxruntime on windows?
|
For those of you who are interested in static libraries of onnxruntime, please have a look at For instance, if you want to have static onnxruntime lib for windows, please use |
Use build flag --build_shared_lib, we can get onnxruntime.lib, onnxruntime.dll, which can be dynamically linked,
While how to build a single onnxruntime static lib like onnxruntime.lib for static link?
I had tried to change the following code in onnxruntime.cmake to get a single onnxruntime.lib,but it can't be resolve when used in vs2017, I cannot figure out why, can someone meet the same issue?
add_library(onnxruntime SHARED ${onnxruntime_session_srcs})
=>
add_library(onnxruntime STATIC ${onnxruntime_session_srcs})
and use flag --build_shared_lib to trigger the onnxruntime.cmake build
The text was updated successfully, but these errors were encountered: