[cfe-dev] Latest clang and dllimport

Edward Diener eldlistmailingz at tropicsoft.com
Tue Jul 21 17:35:52 PDT 2015


On 7/21/2015 5:47 PM, Yaron Keren wrote:
> The error reported is with mingw 5.1.0 which is failry new.
> Maybe previous clangs were ok using previous versions of the mingw-w64
> headers?

Actually previous clang are using mingw headers and the 
__declspec(dllimport) which is WINBASEAPI in mingw-64 is nothing in 
mingw. It looks as if Boost will have to use logic to see whether mingw 
or mingw-64 is being used.

>
>
> 2015-07-22 0:39 GMT+03:00 Hans Wennborg
> <hans at chromium.org
> <mailto:hans at chromium.org>>:
>
>     Hi Edward,
>
>     I'm using this code to reproduce the issue you're seeing:
>
>        extern "C" void sleep(unsigned ms);
>        void f() {
>          sleep(1000);
>        }
>        extern "C" __declspec(dllimport) void sleep(unsigned ms);
>
>     Compiling with "clang -target i686-pc-win32 -c a.cc" produces the
>     error you describe.
>
>     This produces an error both with both 3.5, 3.6 and trunk for me. Is it
>     possible that something has changed in your code, or that something is
>     getting #ifdef'ed differently based on the clang version?
>
>     The problem here is that Clang doesn't want to change the
>     "dllimport"-ness of sleep() after it has been called. If you try to
>     add the dllimport attribute before sleep() has been used, Clang will
>     just warn.
>
>       - Hans
>
>     On Tue, Jul 21, 2015 at 12:36 PM, Edward Diener
>     <eldlistmailingz at tropicsoft.com
>     <mailto:eldlistmailingz at tropicsoft.com>> wrote:
>      > In the latest clang built from source, if a function is
>     mismatched as to a
>      > difference in dllimport attributes clang produces an error. As in:
>      >
>      >
>     C:\Utilities\mingw-w64\i686-5.1.0-posix-dwarf-rt_v4-rev0\mingw32\i686-w64-mingw32\include\synchapi.h:127:26:
>      > error: redeclaration of 'Sleep' cannot add 'dllimport' attribute
>      >   WINBASEAPI VOID WINAPI Sleep (DWORD dwMilliseconds);
>      >                          ^
>      > ..\..\..\boost/smart_ptr/detail/yield_k.hpp:67:29: note: previous
>      > declaration is here
>      >   extern "C" void __stdcall Sleep( unsigned long ms );
>      >
>      > Changing the latter to:
>      >
>      >   extern "C" __declspec(dllimport) void __stdcall Sleep( unsigned
>     long ms );
>      >
>      > fixes the problem for clang.
>      >
>      > Earlier versions of clang ( 3.4.1, 3.5.2, 3.6.1 ) did not have
>     this problem.
>      > Is there a __has_feature or __has_extension that I can use to
>     test this
>      > change in the latest clang ? The previous versions are also happy
>     with the
>      > __declspec(dllimport) added in the declaration so even without a
>      > __has_feature or __has_extension I can just test for clang on
>     Windows, but I
>      > like to be as precise as possible in Boost code.





More information about the cfe-dev mailing list