tag:help.appveyor.com,2012-11-13:/discussions/questions/20396-openssl-pre-installed-version-bundlingAppVeyor: Discussion 2018-10-19T08:18:46Ztag:help.appveyor.com,2012-11-13:Comment/452610672018-05-11T05:21:44Z2018-05-11T05:23:39ZOpenSSL pre-installed version bundling<div><p>I'm not a C++ dev so pardon my ignorance, but I'm trying to understand this paragraph,<br></p>
<pre>
<code>
The libeay32MT version under \VC\lib\ is supposed to be statically linked to the MSVC runtimes but not a static library itself, right? But
when using /MD for dynamic linking to the statically linked libeay32MT in order to not have to bundle MSVC runtimes, which means
having to ship the .dll along with the application, the dll itself requires the runtime. Have not found any different pre-installed versions of
the dlls that are statically linked.</code>
</pre>
My understanding is that <code>/MD</code> flag links to runtime with dependency on <em>msvcr<versionNumber>.dll</em> whereas <code>/MT</code> flag is conventional static linking. So isn't it the latter flag that you want here?</div>Owen McDonnelltag:help.appveyor.com,2012-11-13:Comment/452610672018-05-11T11:10:38Z2018-05-11T11:10:38ZOpenSSL pre-installed version bundling<div><p>No, that's not right. /MD is a compiler flag which tells it to make a dynamically loadable module, whereas /MT tells it to create a static library.</p>
<p>That has nothing to do with how the C/C++ runtimes were linked, which is done by linker not compiler and can be either statically or dynamically.</p>
<p>So in essence can build either static libraries (/MT) or dynamic libraries (/MD) which are linked either statically or dynamically to their C/C++ runtimes for a total of 8 permutations.</p>
<p>This is why there are 8 versions of the openssl libraries, two dynamic libraries, libeay32MD and libeay32MT, referring to dynamic or static linking to MSVC runtimes, and static/libeay32MT, static/libeay32MD for static library of the same. static/libeay32MD is a static library with dynamic linking to MSVC runtimes which in some scenarios is preferred.</p>
<p>In this case only building a dynamic library is an option as it is a library to be loaded into application, not a stand alone program. So /MD compiler flag with dynamic openssl libraries is the only option. The use case does require static links to MSVC runtimes, however, so as not to require the user to install them.</p>
<p>To do that, the library was set to link against the dynamic libeay32MT. As they are dynamically loaded, they require that the .dlls are shipped. See build output: <a href="https://ci.appveyor.com/project/pkittenis/ssh2-python/build/job/0k7qs75gwn8fkg9f">https://ci.appveyor.com/project/pkittenis/ssh2-python/build/job/0k7...</a></p>
<p>The issue as far as I can see is that the dynamic libeay32MT versions of the library are lacking their equivalent statically linked with MSVC runtimes .dlls to distribute with. libeay32MT does not require MSVC runtimes but the dlls do, making the *eay32MT libraries moot. These dlls are available in other binary distributions ( <a href="https://indy.fulgan.com/SSL">https://indy.fulgan.com/SSL</a>), but not in the pre-installed appveyor openssl.</p></div>bf9rczko2uq9tag:help.appveyor.com,2012-11-13:Comment/452610672018-05-11T11:15:05Z2018-05-11T11:15:05ZOpenSSL pre-installed version bundling<div><p>For reference, the env variable or cmake flag to link with static MSVC runtimes is OPENSSL_MSVC_STATIC_RT. This in turn compiles against *eay32MT. It is separate from OPENSSL_USE_STATIC_LIBS which will compile against static/<..>.</p>
<p>See <a href="https://cmake.org/cmake/help/v3.10/module/FindOpenSSL.html">https://cmake.org/cmake/help/v3.10/module/FindOpenSSL.html</a></p></div>bf9rczko2uq9tag:help.appveyor.com,2012-11-13:Comment/452610672018-05-14T14:12:49Z2018-05-14T14:12:49ZOpenSSL pre-installed version bundling<div><p>Should also point out that linking against static MT libraries but compiling with /MD for a dynamic library is also not an option.</p>
<p>That requires that the same compiler was used for both the library to be linked as well as the dynamic library or the MSVC run times will not match, resulting in errors.</p>
<p>Unfortunately the only option, other than downloading statically linked dlls from another distribution, is to build OpenSSL on every job with multiple compilers - not a very attractive option to say the least.</p></div>bf9rczko2uq9tag:help.appveyor.com,2012-11-13:Comment/452610672018-05-14T17:32:37Z2018-05-14T17:32:37ZOpenSSL pre-installed version bundling<div><p>Again, apologies for not having too much experience with the subtleties of c++ static/dynamic linking. But, if you'll indulge me, I've a simple question... What is the difference between the 'libeay32.dll' at <code>C:\OpenSSL-Win32</code> on the AppVeyor build image and the one of the same name in the binary distributions you linked to?</p></div>Owen McDonnelltag:help.appveyor.com,2012-11-13:Comment/452610672018-05-15T08:44:16Z2018-05-15T08:44:16ZOpenSSL pre-installed version bundling<div><p>No worries, not too familiar with these windows specifics either.</p>
<p>The difference is the ones in <code>C:\OpenSSL-Win32</code> are linked dynamically with MSVC run times meaning they require the MSVC dlls where as the ones from the other binary distribution are linked statically and do not.</p>
<p>Have attached dependency walker screenshots for each with the openssl dll dependencies circled. The one from appveyor has a dependency on msvcr120.dll whereas the other does not.</p></div>bf9rczko2uq9