Boost C++ Libraries: Ticket #5964: Linkage fails with cross-compiled boost.thread https://svn.boost.org/trac10/ticket/5964 <p> I am cross-compiling boost 1.47 using </p> <p> $ x86_64-w64-mingw32-g++ --version </p> <p> x86_64-w64-mingw32-g++ (GCC) 4.5.4 20110822 (prerelease) </p> <p> On Linux box with the following command: </p> <p> ./b2 -a toolset=gcc target-os=windows threading=multi threadapi=pthread runtime-link=static --layout=versioned --build-type=complete install </p> <p> user-config.jam contains the following: </p> <p> using gcc : mingw : x86_64-w64-mingw32-g++ ; </p> <p> After that a linkage failed when building my project. I reproduced it with simple test program: </p> <p> #include &lt;boost/thread.hpp&gt; #include &lt;iostream&gt; </p> <p> using namespace std; </p> <p> struct test { </p> <blockquote> <p> void operator()() { cout &lt;&lt; "Called" &lt;&lt; endl; } </p> </blockquote> <p> }; </p> <p> int main() { </p> <blockquote> <p> test test_obj; boost::thread thr(test_obj); thr.join(); </p> </blockquote> <p> } </p> <p> The output looks like </p> <p> $ x86_64-w64-mingw32-g++ -Wall test_boost.cpp -I ./3rdparty/boost/include/boost-1_47 -L ./3rdparty/boost/lib -lboost_thread-mgw-mt-s-1_47 -o test_boost.exe In file included from ./3rdparty/boost/include/boost-1_47/boost/thread/win32/thread_data.hpp:12:0, </p> <blockquote> <p> from </p> </blockquote> <p> ./3rdparty/boost/include/boost-1_47/boost/thread/thread.hpp:15, </p> <blockquote> <p> from ./3rdparty/boost/include/boost-1_47/boost/thread.hpp:13, from test_boost.cpp:2: </p> </blockquote> <p> ./3rdparty/boost/include/boost-1_47/boost/thread/win32/thread_heap_alloc.hpp:59:40: warning: inline function ‘void* boost::detail::allocate_raw_heap_memory(unsigned int)’ declared as dllimport: attribute ignored ./3rdparty/boost/include/boost-1_47/boost/thread/win32/thread_heap_alloc.hpp:69:39: warning: inline function ‘void boost::detail::free_raw_heap_memory(void*)’ declared as dllimport: attribute ignored /tmp/ccSmsBnO.o:test_boost.cpp:(.text+0xde): undefined reference to `<span class="underline">imp</span>ZN5boost6thread4joinEv' /tmp/ccSmsBnO.o:test_boost.cpp:(.text+0xfb): undefined reference to `<span class="underline">imp</span>ZN5boost6threadD1Ev' /tmp/ccSmsBnO.o:test_boost.cpp:(.text+0x1c3): undefined reference to `<span class="underline">imp</span>ZN5boost6threadD1Ev' /tmp/ccSmsBnO.o:test_boost.cpp:(.text$_ZN5boost6threadC1I4testEET_NS_10disable_ifINS_14is_convertibleIRS3_NS_6detail13thread_move_tIS3_EEEEPNS0_5dummyEE4typeE[boost::thread::thread&lt;test&gt;(test, boost::disable_if&lt;boost::is_convertible&lt;test&amp;, boost::detail::thread_move_t&lt;test&gt; &gt;, boost::thread::dummy*&gt;::type)]+0xd5): undefined reference to `<span class="underline">imp</span>ZN5boost6thread12start_threadEv' collect2: ld returned 1 exit status </p> <p> The same scenario works fine when linking with dynamic libboost_thread. Both static and dynamic builds work fine for Linux. </p> <p> When I add define </p> <p> -DBOOST_THREAD_USE_LIB=1 </p> <p> it results in following: </p> <p> ./3rdparty/boost/include/boost-1_47 ./3rdparty/boost/lib/libboost_thread-mgw-mt-1_47.a /home/del/pthreads-w64/pthreads/libpthreadGC2.a -o test_boost.exe ./3rdparty/boost/lib/libboost_thread-mgw-mt-1_47.a(thread.o): duplicate section `.data$_ZTIN5boost6detail16thread_data_baseE[typeinfo for boost::detail::thread_data_base]' has different size ./3rdparty/boost/lib/libboost_thread-mgw-mt-1_47.a(thread.o):thread.cpp:(.text+0x3a00): multiple definition of `boost::detail::thread_data_base::~thread_data_base()' /tmp/ccROgsoo.o:test_boost.cpp:(.text$_ZN5boost6detail16thread_data_baseD2Ev[boost::detail::thread_data_base::~thread_data_base()]+0x0): first defined here ./3rdparty/boost/lib/libboost_thread-mgw-mt-1_47.a(thread.o):thread.cpp:(.text+0x3a00): multiple definition of `boost::detail::thread_data_base::~thread_data_base()' /tmp/ccROgsoo.o:test_boost.cpp:(.text$_ZN5boost6detail16thread_data_baseD1Ev[boost::detail::thread_data_base::~thread_data_base()]+0x0): first defined here ./3rdparty/boost/lib/libboost_thread-mgw-mt-1_47.a(thread.o):thread.cpp:(.text+0x3d50): multiple definition of `boost::detail::thread_data_base::~thread_data_base()' /tmp/ccROgsoo.o:test_boost.cpp:(.text$_ZN5boost6detail16thread_data_baseD0Ev[boost::detail::thread_data_base::~thread_data_base()]+0x0): first defined here collect2: ld returned 1 exit status </p> <p> I have reproduced it with boost 1.43, 1.46.1, 1.47 and latest (74606) revision from svn. Tried two differen mingw-w64 gcc versions: 4.5.4 and 4.7.0. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5964 Trac 1.4.3 Victor Leschuk <vleschuk@…> Fri, 30 Sep 2011 10:09:59 GMT <link>https://svn.boost.org/trac10/ticket/5964#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5964#comment:1</guid> <description> <p> Sorry, I forgot to specify my e-mail before posting this. Please add it whoever has rights to: vleschuk@… </p> </description> <category>Ticket</category> </item> <item> <author>vleschuk@…</author> <pubDate>Tue, 11 Oct 2011 05:37:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5964#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5964#comment:2</guid> <description> <p> I performed few simple tests: </p> <p> The samples were compiled by the following command: x86_64-w64-mingw32-g++ -I ./boost/svn_74606-win64/include/boost-1_48 -o test.exe test.cpp ./boost/svn_74606-win64/lib/libboost_thread-mgw-mt-1_48.a </p> <p> 1) </p> <p> int main() { } </p> <p> ok </p> <p> 2) </p> <p> #include &lt;boost/thread.hpp&gt; int main() { } </p> <p> ok </p> <p> 3) </p> <p> #include &lt;boost/thread.hpp&gt; int main() { </p> <blockquote> <p> boost::thread thr; </p> </blockquote> <p> } </p> <p> NOT ok: </p> <p> /tmp/ccm0ryQa.o:kk.cpp:(.text+0x17): undefined reference to `<span class="underline">imp</span>ZN5boost6threadC1Ev' /tmp/ccm0ryQa.o:kk.cpp:(.text+0x27): undefined reference to `<span class="underline">imp</span>ZN5boost6threadD1Ev' </p> <p> Hope this helps... </p> </description> <category>Ticket</category> </item> <item> <author>vleschuk@…</author> <pubDate>Tue, 18 Oct 2011 07:50:30 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5964#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5964#comment:3</guid> <description> <p> I reviewed the boost headers and found out that the second problem (with multiple definition of thread_data_base is caused because during build of boost itself posix threads are used, but when compiling headers for the application threadapi is being detected by compiler and OS defines. So it was trying to use Win32 threads. This can be solved by using BOOST_THREAD_POSIX define </p> <p> The following command works fine: </p> <p> x86_64-w64-mingw32-g++ -DBOOST_THREAD_POSIX -DBOOST_THREAD_USE_LIB -I/path/to/pthreads/headers -I/path/to/boost/headers -o test.exe test_boost.cpp -L/path/to/boost/lib -lboost_thread-mgw-mt-s-1_48 -lpthreadGC2 -static-libgcc -static-libstdc++ </p> <p> So I think this ticket should be closed as "not a bug". </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 18 Oct 2011 08:05:40 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5964#comment:4 https://svn.boost.org/trac10/ticket/5964#comment:4 <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">invalid</span> </li> </ul> Ticket