fix link error on shared libs with -MT#20834
Conversation
1a6460e to
0bb6677
Compare
This is very unusual setup. Details:
|
modules/highgui/CMakeLists.txt
Outdated
| @@ -164,7 +164,10 @@ if(APPLE) | |||
| endif() | |||
|
|
|||
| if(MSVC) | |||
There was a problem hiding this comment.
Please use this condition instead (got from OpenCVCRTLinkage.cmake):
-if(MSVC)
+if(MSVC AND NOT BUILD_SHARED_LIBS AND BUILD_WITH_STATIC_CRT)There was a problem hiding this comment.
Is it intended that the condition is only executed when BUILD_WITH_STATIC_CRT is true? The intention seems to be opposite. Maybe it's a precedence error in OpenCVCRTLinkage.cmake?
The intention was to remove stray static CRT when modules are linked against dependencies linked with -MT. The condition now applies only to static CRT builds.
There was a problem hiding this comment.
AFAIK, "nodefaultlib" may be used for supporting switching between single-threaded / multi-threaded CRT on application level (outside of OpenCV build) using just single set of static OpenCV binaries.
This may work several years ago, but modern MSVS compilers use /FAILIFMISMATCH:RuntimeLibrary= check. So that approach is unlikely work.
Also commits history contains mentions about MinGW fixes.
I believe we should think how to drop "nodefault" magic, but probably not in this PR.
Lets fix the compilation problem of your case first (please apply the diff above).
0bb6677 to
3d93675
Compare
To reproduce the link failure, use
The linker then fails to include any CRT version.