Boost logo

Boost :

Subject: Re: [boost] [winapi] [thread] Conflicting declarations on MinGW
From: Agustín K-ballo Bergé (kaballo86_at_[hidden])
Date: 2015-12-31 09:50:10

On 12/31/2015 11:32 AM, Andrey Semashev wrote:
> On 2015-12-31 15:47, Agustín K-ballo Bergé wrote:
>> On 12/31/2015 7:59 AM, Andrey Semashev wrote:
>>> On 2015-12-31 13:40, Antony Polukhin wrote:
>>>> Hi,
>>>> Some of the Boost.DLL tests produce following warnings:
>>>> ../boost/thread/win32/thread_primitives.hpp:175:83: warning:
>>>> declaration of
>>>> 'void* boost::detail::win32::GetModuleHandleA(const char*)' with C
>>>> language
>>>> linkage
>>>> ../boost/detail/winapi/dll.hpp:47:1: warning: conflicts with previous
>>>> declaration 'HINSTANCE__*
>>>> GetModuleHandleA(boost::detail::winapi::LPCSTR_)'
>>>> ../boost/thread/win32/thread_primitives.hpp:195:94: warning:
>>>> declaration of
>>>> 'int (__attribute__((__stdcall__)) *
>>>> boost::detail::win32::GetProcAddress(void*, const char*))()' with C
>>>> language linkage
>>>> ../boost/detail/winapi/dll.hpp:82:1: warning: conflicts with previous
>>>> declaration 'int (__attribute__((__stdcall__)) *
>>>> GetProcAddress(boost::detail::winapi::HMODULE_,
>>>> boost::detail::winapi::LPCSTR_))()'
>>>> Andrey, Vicente what's the best way to resolve such issues?
>>> IMO, Boost.Thread needs to be ported to Boost.WinAPI.
>>> boost/thread/win32/thread_primitives.hpp declares extern "C" functions
>>> in its own namespace, while Windows SDK and Boost.WinAPI declare them in
>>> the global namespace.
>> Declaring extern "C" functions in a namespace is perfectly fine.
>> Frankly, I'm surprised and disappointed that Boost.WinAPI does not do
>> it, and that it will litter the global namespace instead.
> It did, until it caused problems with clang - similar to the ones quoted
> by Antony above.

I made a little experiment to try to understand what you are saying:

As you can see, this reproduces both the gcc warning and a clang error,
but only for the conflicting declaration of `bar`. The difference in
namespace for `foo` is irrelevant, as the standard says.

>> The warning comes from the use of different arguments and/or return type
>> in the declarations. I'm guessing Boost.WinAPI is using winapi's typed
>> handles, while we can see in the warning message that Boost.Thread uses
>> just `void`.
> The types in Boost.WinAPI are the same as the ones in Windows SDK (sans
> the typedefs, which I assume are not essential). There are no structs in
> the mentioned functions, and as far as I can see the types in
> Boost.Thread are also the same. So the only difference seems to be the
> namespace in which the functions are declared.

The Windows SDK uses dummy structs to bring some sort of type safety to
the otherwise untyped handles. As you can see in the warning,
Boost.Thread is using plain `void*` instead, probably coming from here

That is the source of the problem, not the namespaces in which the
extern "C" functions are declared.


Agustín K-ballo Bergé.-

Boost list run by bdawes at, gregod at, cpdaniel at, john at