Enable using dynamic runtime libs with when disabling shared libs for Windows
|Status:||Closed||Start date:||10 Jan 2017|
|Assignee:||Robin Mills||% Done:|
|Category:||build||Estimated time:||4.00 hours|
This patch enables using dynamic runtime libraries when using NO_SHARED libraries with cmake instead of the staticly linked version. For use and tested in Windows with CMake / MSVC.
#2 Updated by Robin Mills almost 2 years ago
- % Done changed from 0 to 50
- Estimated time set to 2.00
Thanks for reporting this. We made a policy decision (in 2008) to support "all dlls, or all static". Mikayel asked for "dlls with static run-time". This is a lethal combination which I investigated and discussed in detail. http://dev.exiv2.org/issues/1157
The problem is that linking DLLs with static run-time can result in several copies of run-time library because every dll (eg libexiv2.dll contains a static run-time library) and the executable/client app have their own run-time library. If you open a FILE* in libexiv2.dll and fclose() it in the application, the application will crash. That typically does not happen, however memory resources (new/delete) often cross the library boundaries with very bad consequences.
I think static libraries that all use a shared dynamic runtime will work. Thanks for your patch. I'll review this.
#3 Updated by Ben Touchette almost 2 years ago
The patch was made to leave things the way they work as is, but gives the option of creating a static only lib that requires linking to dynamic runtimes a way to do so. Yes the whole app needs to be linked that way as well else it just won't link i would think :)
#4 Updated by Robin Mills almost 2 years ago
- Estimated time changed from 2.00 to 4.00
Patch submitted r4740. Thanks very much to be for reporting this, investigating this matter and providing the patch.
The origins of this go back to 2012 when the file CMakeList_msvc.txt was created in the project to support MSVC/CMake. That project was shelved and complete in 2014. The 2014 project does handle static and shared libraries. However I forgot to cause the static library to use the static runtime. Thank You for completing this. The msvc build environment is "all shared" or "all static". With msvc, if you generate a DLL, it will use the dynamic runtime. If you generate a static library, it will use the static runtime.
1) It's very likely that contrib/cmakeBuild.cmd requires an update to convert options
--static/--shared to set the CMake option:
-DEXIV2_ENABLE_DYNAMIC_RUNTIME=OFF/ON I will investigate this.
2) Testing on MSVC 2005/8/10/12/13/15 (in 32 and 64 bit) is very time consuming. If this patch survives the nightly build on the buildserver (which builds shared libraries), I'm going to allow it to ship in v0.26 as the patch has done no harm.
3) I personally don't care for using the "d" in ./CMakeLists.txt:
set(CMAKE_DEBUG_POSTFIX "d"). This has the effect of adding a 'd' to library file. So libexiv2.dll becomes libexiv2d.dll This is different from the libraries generated by msvc project files.
#5 Updated by Robin Mills almost 2 years ago
- Status changed from Assigned to Closed
- % Done changed from 50 to 100
Good News, Ben.
r4741 I've set -DEXIV2_ENABLE_DYNAMIC_RUNTIME=OFF for when cmakeBuild.cmd --static is used. It's working. I've tested both --static and --shared. Options --static and --shared are exclusive because of the architecture of CMake/Visual Studio. I have a feeling it was working correctly anyway (although I'm not sure how!).
I've tested that Debug DLLs use the debug share run-time library and the DLL is exiv2d.dll (and it uses the zlibd.dll)
C:\Users\rmills\gnu\exiv2\build\>cmd /c "vcvars 2005 && cmakeBuild --shared --rebuild --pause --config Debug"
C:\Users\rmills\gnu\exiv2\build\dist\2005\x64\dll\Debug\bin>dir *.dll Volume in drive C has no label. Volume Serial Number is 0899-EF40 Directory of C:\Users\rmills\gnu\exiv2\build\dist\2005\x64\dll\Debug\bin 2017-03-17 03:56 PM 5,929,984 exiv2d.dll 2017-03-17 03:53 PM 310,784 expat.dll 2017-03-17 03:52 PM 181,760 zlibd.dll 3 File(s) 6,422,528 bytes 0 Dir(s) 13,136,359,424 bytes free C:\Users\rmills\gnu\exiv2\build\dist\2005\x64\dll\Debug\bin>