Boost logo

Boost :

Subject: Re: [boost] [Boost-users] cross-compilation x86_64-w64-ming32: undefined reference to `InterlockedIncrement'
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-09-23 07:37:08


On Mon, Sep 23, 2013 at 2:46 PM, Frédéric Bron <frederic.bron_at_[hidden]>wrote:

> > I probably missed the original problem, but the patch doesn't look
> correct
> > to me. The section guarded with "defined( BOOST_MSVC ) || defined(
> > BOOST_INTEL_WIN )" is obviously targeted for compilers supporting
> > interlocked intrinsics, which gcc isn't. MinGW should probably be handled
> > by the last section of the #if/elif/endif sequence. Anyway, what problem
> > are you trying to fix?
>
> Here is what I get when build an application with boost and mingw-w64
> targeting x86_64:
>
> /usr/x86_64-w64-mingw32/sys-
> root/mingw/lib/../lib/libboost_thread-mt.a(thread.o):(.text+0x286):
> undefined reference to `InterlockedIncrement'
>
> /usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libboost_thread-mt.a(thread.o):(.text+0x3e7):
> undefined reference to `InterlockedDecrement'
>
> /usr/lib64/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld:
>
> /usr/x86_64-w64-mingw32/sys-root/mingw/lib/../lib/libboost_thread-mt.a(thread.o):
> bad reloc address 0x8 in section `.data'
>
> I have been able to solve this by defining BOOST_USE_WINDOWS_H but
> this creates issues with Unicode when I also use wxWidgets. The patch
> proposed solves the issue. I recognise that I say that gcc should be
> considered as MSVC with regards to these Interlocked things which I do
> not understand. It may seem strange but it works. What's wrong with
> it? Basically, I just #include <intrin.h>; what's wrong with that?
>

It makes the code less clear. Also, intrin.h is an MSVC-specific header and
I'm not sure it's portable across different versions of MinGW.

Does it help if you just replace:

  #if defined(__MINGW64__)
  #define BOOST_INTERLOCKED_IMPORT
  #else
  #define BOOST_INTERLOCKED_IMPORT __declspec(dllimport)
  #endif

with

  #define BOOST_INTERLOCKED_IMPORT BOOST_SYMBOL_IMPORT

and no other changes? If that fixes the problem, this would be a more
appropriate solution for 1.55. In the long term it might be worthwhile to
use gcc atomic intrinsics to implement BOOST_INTERLOCKED* macros.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk