Boost C++ Libraries: Ticket #13077: Linking to static 64bit libboost_thread fails DLL initialization https://svn.boost.org/trac10/ticket/13077 <p> If DLL links to static boost thread library the dll can not initialize and any exe that uses the DLL fails with error code <code></code><code>(0xc0000142) 'DLL Initialization Failed'</code><code></code>. </p> <p> I've attached an minimal example project to demonstrate the problem. The package includes static boost libraries that were built with steps given below. </p> <p> This example produces a thedll.dll that links libboost_thread (does not use any headers) and then theexe.exe that links to thedll.dll. theexe.exe fails to start with attached error prompt. </p> <p> Root cause of the fail is beyond me, but I traced debugger to dll_dllmain.cpp on line 57. Here _initterm_e returns non-zero value and thedll.dll init fails. <code></code><code>This happens only if libboost_thread is linked to the dll</code><code></code>. </p> <p> Environment: </p> <ul><li>Visual Studio 15 2017 Community Edition </li><li>64 bit builds. </li><li>CMake generator 'Visual Studio 15 2017 Win64'. </li></ul><p> Boost build steps: (Called from VS environment cmd shell. Tools -&gt; Visual Studio Command Prompt) </p> <ol><li>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat amd64 </li><li>bootstrap.bat </li><li>bjam -j4 architecture=x86 address-model=64 link=static stage </li><li>bjam --prefix=C:\opt\boost architecture=x86 address-model=64 link=static install </li></ol> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13077 Trac 1.4.3 Teemu Ikonen <teemu.ikonen@…> Fri, 16 Jun 2017 08:26:44 GMT <link>https://svn.boost.org/trac10/ticket/13077#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13077#comment:1</guid> <description> <p> Maximum attachment size was mere few hundred kb's so I'm linking stuff here. Also I can't use proper urls as Trac will reject my comment as spam.. sigh. </p> <p> project <br /> </p> <blockquote> <p> ikonen.me/boostthread/boostproblem.zip </p> </blockquote> <p> Some debug screencaptures <br /> </p> <blockquote> <p> ikonen.me/boostthread/launcherror.png <br /> ikonen.me/boostthread/dllinitfailure.png <br /> ikonen.me/boostthread/vs_debugoutput.png <br /> </p> </blockquote> </description> <category>Ticket</category> </item> <item> <author>Teemu Ikonen <teemu.ikonen@…></author> <pubDate>Sun, 18 Jun 2017 20:37:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13077#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13077#comment:2</guid> <description> <p> Traced the error to a call to <code>PVAPI on_tls_prepare()</code>. This function gets called by <code>_initterm_e</code> that expects it to return 0 on success. </p> <p> However in boost PVAPI is defined as void return type. I think this test is wrong for _MSC_VER 1910 in <code>tss_pe.cpp</code>. </p> <pre class="wiki"> #if (_MSC_VER &lt; 1300) || (_MSC_VER &gt; 1900) // 1300 == VC++ 7.0, 1900 == VC++ 14.0 typedef void (__cdecl *_PVFV)(); #define INIRETSUCCESS #define PVAPI void __cdecl #else typedef int (__cdecl *_PVFV)(); #define INIRETSUCCESS 0 #define PVAPI int __cdecl #endif </pre><p> The runtime initializer function is supposed to return an int </p> <pre class="wiki">/C/Program Files (x86) $ find . -name "*.h" -print0|xargs -0 grep _PIFV | grep typedef find: ‘./Google/CrashReports’: Permission denied ./Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/crt/src/vcruntime/internal_shared.h: typedef int (__cdecl* _PIFV)(void); ./Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/crt/src/vcruntime/minternal.h: typedef int (__clrcall* _PIFVM)(void); ./Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/crt/src/vcruntime/vcruntime_internal.h:typedef int (__cdecl* _PIFV)(void); ./Microsoft Visual Studio/Shared/14.0/VC/crt/src/vcruntime/internal_shared.h: typedef int (__cdecl* _PIFV)(void); ./Microsoft Visual Studio/Shared/14.0/VC/crt/src/vcruntime/minternal.h: typedef int (__clrcall* _PIFVM)(void); ./Microsoft Visual Studio/Shared/14.0/VC/crt/src/vcruntime/vcruntime_internal.h:typedef int (__cdecl* _PIFV)(void); ./Windows Kits/10/Include/10.0.10240.0/ucrt/corecrt_startup.h:typedef int (__cdecl* _PIFV)(void); ./Windows Kits/10/Include/10.0.15063.0/ucrt/corecrt_startup.h:typedef int (__cdecl* _PIFV)(void); </pre> </description> <category>Ticket</category> </item> <item> <author>Teemu Ikonen <teemu.ikonen@…></author> <pubDate>Mon, 19 Jun 2017 08:33:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13077#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13077#comment:3</guid> <description> <p> This problem has been fixed in commit: <a class="ext-link" href="https://github.com/boostorg/thread/commit/676521808d2fea63afcf295d8edb6f55df90f97a"><span class="icon">​</span>https://github.com/boostorg/thread/commit/676521808d2fea63afcf295d8edb6f55df90f97a</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 24 Jun 2017 14:32:11 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/13077#comment:4 https://svn.boost.org/trac10/ticket/13077#comment:4 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Tue, 22 Aug 2017 21:59:37 GMT status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/13077#comment:5 https://svn.boost.org/trac10/ticket/13077#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.65.0</span> </li> </ul> Ticket