Boost C++ Libraries: Ticket #4614: Unable to statically link thread lib on mingw/win32 https://svn.boost.org/trac10/ticket/4614 <pre class="wiki">Errors: ../Obj/win32-gcc/Debug/StatTester/StressTester.o:C:\Danil\Src\update\StressTester/Impl/StressTester.cpp:94: undefined reference to `_imp___ZN5boost6thread4joinEv' ../Obj/win32-gcc/Debug/StatTester/StressTester.o: In function `thread&lt;boost::_bi::bind_t&lt;unsigned int, boost::_mfi::mf0&lt;unsigned int, boost::asio::io_service&gt;, boost::_bi::list1&lt;boost::_bi::value&lt;boost::asio::io_service*&gt; &gt; &gt; &gt;': C:\Danil\Src\update\StressTester/../../boost/mingw/boost/boost/thread/detail/thread.hpp:204: undefined reference to `_imp___ZN5boost6thread12start_threadEv' ../Obj/win32-gcc/Debug/StatTester/StressTester.o:C:\Danil\Src\update\StressTester/../../boost/mingw/boost/boost/checked_delete.hpp:34: undefined reference to `_imp___ZN5boost6threadD1Ev' </pre><p> Works fine with boost 1.43 </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4614 Trac 1.4.3 Steven Watanabe Mon, 30 Aug 2010 14:40:34 GMT <link>https://svn.boost.org/trac10/ticket/4614#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:1</guid> <description> <p> From the error message, it looks like you compiled to link to dll. Is either BOOST_THREAD_DYN_LINK or BOOST_ALL_DYN_LINK defined? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 31 Aug 2010 12:51:44 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:2</guid> <description> <p> Looks like :) But BOOST_THREAD_DYN_LINK/BOOST_ALL_DYN_LINK is not defined by me. </p> </description> <category>Ticket</category> </item> <item> <author>Danil Ilinykh <woodroof@…></author> <pubDate>Wed, 01 Sep 2010 06:57:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:3</guid> <description> <p> If I try dynamic linking, it links well, but I get error while executing application: The application failed to initialize properly (0xc0000005) </p> </description> <category>Ticket</category> </item> <item> <author>Danil Ilinykh <woodroof@…></author> <pubDate>Thu, 02 Sep 2010 07:24:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:4</guid> <description> <p> Problem is here: file /boost/thread/detail/config.hpp:40 (boost version 1.44) </p> <table class="wiki"> <tr>I added "<td> defined(<span class="underline">MINGW32</span>)" at the end of line and all works fine (with exception if bug 4258, walkaround writed here: <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/4258#comment:6"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/4258#comment:6</a>) </td></tr></table> </description> <category>Ticket</category> </item> <item> <author>koradlow@…</author> <pubDate>Mon, 11 Oct 2010 11:38:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:5</guid> <description> <p> I recompiled the lib with the proposed changes to config.hpp:40 </p> <pre class="wiki">if defined(BOOST_MSVC) || defined(BOOST_INTEL_WIN) || defined(MINGW32) || defined(BOOST_MINGW32) </pre><p> But I still get the same linker error as mentioned above trying to link statically. Using boost 1.44, mingw 3.15 and gcc 4.4.0, dynamically linking works fine though </p> <p> This is my link command which causes the errors </p> <pre class="wiki">g++.exe -static -o .../main.o -L/D/boost_1_44_0/stage/lib /D/boost_1_44_0/stage/lib/libboost_thread-mgw44-mt-sd-1_44.a </pre><p> btw: I also had to apply this patch <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/4315"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/4315</a> </p> </description> <category>Ticket</category> </item> <item> <author>koradlow@…</author> <pubDate>Tue, 12 Oct 2010 08:32:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:6</guid> <description> <p> Found a solution that works for me: apply this patch: <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/</a> recompile, add the preprocessor directive: <strong>BOOST_THREAD_USE_LIB</strong><br /> Now I can link against the static librarary without any problems </p> </description> <category>Ticket</category> </item> <item> <author>koradlow@…</author> <pubDate>Tue, 12 Oct 2010 08:33:58 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4614#comment:6" title="Comment 6">koradlow@…</a>: complete Link: <a class="ext-link" href="https://svn.boost.org/trac/boost/ticket/4258"><span class="icon">​</span>https://svn.boost.org/trac/boost/ticket/4258</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Bryce Adelstein Lelbach</dc:creator> <pubDate>Thu, 21 Oct 2010 19:11:02 GMT</pubDate> <title>severity, milestone changed; cc set https://svn.boost.org/trac10/ticket/4614#comment:8 https://svn.boost.org/trac10/ticket/4614#comment:8 <ul> <li><strong>cc</strong> <span class="trac-author">Bryce Adelstein Lelbach</span> added </li> <li><strong>severity</strong> <span class="trac-field-old">Regression</span> → <span class="trac-field-new">Showstopper</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost-1.45.0</span> </li> </ul> <p> Not a duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4258" title="#4258: Bugs: Linking with boost thread does not work on mingw/gcc 4.5 (closed: fixed)">#4258</a>, I believe, though the fix given in <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4258" title="#4258: Bugs: Linking with boost thread does not work on mingw/gcc 4.5 (closed: fixed)">#4258</a> apparently works for this. </p> Ticket Anthony Williams Fri, 22 Oct 2010 09:54:22 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/4614#comment:9 https://svn.boost.org/trac10/ticket/4614#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Static linking seems to work fine now <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4258" title="#4258: Bugs: Linking with boost thread does not work on mingw/gcc 4.5 (closed: fixed)">#4258</a> is fixed. </p> Ticket gtoknu Sun, 05 Dec 2010 13:34:57 GMT <link>https://svn.boost.org/trac10/ticket/4614#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:10</guid> <description> <p> nor koradlow answer, nor Danil answer worked for me, any hints? I can't figure it out why I can't link it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>WFrane</dc:creator> <pubDate>Mon, 14 Feb 2011 17:08:51 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:11</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4614#comment:9" title="Comment 9">anthonyw</a>: </p> <blockquote class="citation"> <p> Static linking seems to work fine now <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4258" title="#4258: Bugs: Linking with boost thread does not work on mingw/gcc 4.5 (closed: fixed)">#4258</a> is fixed. </p> </blockquote> <p> It appears that adding <strong>#define BOOST_THREAD_USE_LIB</strong> before other boost thread-related preprocessor directives is still required for static linking when using MinGW (tested using Boost 1.45.0 and MinGW 4.4.1). </p> <p> @gtoknu: This may be too late for you, but adding <strong>#define BOOST_THREAD_USE_LIB</strong> before the include statements for the boost headers worked for me. I also recompiled the boost libraries after modifying config.hpp in the manner indicated by koradlow in comment 5, but I'm not certain that doing so is necessary. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 05 Jan 2012 15:39:39 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:12</guid> <description> <p> Still don't work for me any suggestions? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Karin J</dc:creator> <pubDate>Fri, 06 Jan 2012 16:29:59 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:13</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4614#comment:12" title="Comment 12">anonymous</a>: </p> <blockquote class="citation"> <p> Still don't work for me any suggestions? </p> </blockquote> <p> Try changing the order of the libraries. Some linkers take order into account. I am using Eclipse and it appears that the order that works is exactly opposite to what I assumed; namely, library A depending on library B is listed BEFORE B. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>poiuz</dc:creator> <pubDate>Tue, 14 Feb 2012 16:55:20 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4614#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4614#comment:14</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/4614#comment:11" title="Comment 11">WFrane</a>: </p> <blockquote class="citation"> <p> It appears that adding <strong>#define BOOST_THREAD_USE_LIB</strong> before other boost thread-related preprocessor directives is still required for static linking when using MinGW (tested using Boost 1.45.0 and MinGW 4.4.1). </p> </blockquote> <p> It is still necessary with Boost 1.48 and MinGW GCC 4.6.2. Without <strong>#define BOOST_THREAD_USE_LIB</strong> the example <a href="http://www.boost.org/doc/libs/1_48_0/doc/html/boost_asio/tutorial/tuttimer5.html">Timer5</a> from the Boost.Asio tutorial cannot be linked to the static thread library. </p> </description> <category>Ticket</category> </item> </channel> </rss>