Opened 11 years ago

Closed 11 years ago

#5964 closed Bugs (invalid)

Linkage fails with cross-compiled boost.thread

Reported by: anonymous Owned by: Anthony Williams
Milestone: To Be Determined Component: thread
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

I am cross-compiling boost 1.47 using

$ x86_64-w64-mingw32-g++ --version

x86_64-w64-mingw32-g++ (GCC) 4.5.4 20110822 (prerelease)

On Linux box with the following command:

./b2 -a toolset=gcc target-os=windows threading=multi threadapi=pthread runtime-link=static --layout=versioned --build-type=complete install

user-config.jam contains the following:

using gcc : mingw : x86_64-w64-mingw32-g++ ;

After that a linkage failed when building my project. I reproduced it with simple test program:

#include <boost/thread.hpp> #include <iostream>

using namespace std;

struct test {

void operator()() { cout << "Called" << endl; }

};

int main() {

test test_obj; boost::thread thr(test_obj); thr.join();

}

The output looks like

$ 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,

from

./3rdparty/boost/include/boost-1_47/boost/thread/thread.hpp:15,

from ./3rdparty/boost/include/boost-1_47/boost/thread.hpp:13, from test_boost.cpp:2:

./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 `impZN5boost6thread4joinEv' /tmp/ccSmsBnO.o:test_boost.cpp:(.text+0xfb): undefined reference to `impZN5boost6threadD1Ev' /tmp/ccSmsBnO.o:test_boost.cpp:(.text+0x1c3): undefined reference to `impZN5boost6threadD1Ev' /tmp/ccSmsBnO.o:test_boost.cpp:(.text$_ZN5boost6threadC1I4testEET_NS_10disable_ifINS_14is_convertibleIRS3_NS_6detail13thread_move_tIS3_EEEEPNS0_5dummyEE4typeE[boost::thread::thread<test>(test, boost::disable_if<boost::is_convertible<test&, boost::detail::thread_move_t<test> >, boost::thread::dummy*>::type)]+0xd5): undefined reference to `impZN5boost6thread12start_threadEv' collect2: ld returned 1 exit status

The same scenario works fine when linking with dynamic libboost_thread. Both static and dynamic builds work fine for Linux.

When I add define

-DBOOST_THREAD_USE_LIB=1

it results in following:

./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

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.

Change History (4)

comment:1 by Victor Leschuk <vleschuk@…>, 11 years ago

Sorry, I forgot to specify my e-mail before posting this. Please add it whoever has rights to: vleschuk@…

comment:2 by vleschuk@…, 11 years ago

I performed few simple tests:

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

1)

int main() { }

ok

2)

#include <boost/thread.hpp> int main() { }

ok

3)

#include <boost/thread.hpp> int main() {

boost::thread thr;

}

NOT ok:

/tmp/ccm0ryQa.o:kk.cpp:(.text+0x17): undefined reference to `impZN5boost6threadC1Ev' /tmp/ccm0ryQa.o:kk.cpp:(.text+0x27): undefined reference to `impZN5boost6threadD1Ev'

Hope this helps...

comment:3 by vleschuk@…, 11 years ago

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

The following command works fine:

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++

So I think this ticket should be closed as "not a bug".

comment:4 by anonymous, 11 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.