Broken 'C' compilation when building from Master with MSVC

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Broken 'C' compilation when building from Master with MSVC

John Emmas
Hi guys,

I just updated from git master and noticed a problem when building with
MSVC...

Round about line 427, 'gtypes.h' has added a small section with some
function definitions that look like this:-

       static inline gboolean _GLIB_CHECKED_ADD_U32 (guint32 *dest,
guint32 a, guint32 b) {
           *dest = a + b; return *dest >= a; }

Unfortunately, MSVC won't compile the above if I try to compile as 'C'
code.  It compiles fine if I comment out the 'inline' keyword - but
otherwise, I get the following compiler error for each of the newly
added functions in that section:-

       error C2054: expected '(' to follow 'inline'

FWIW these particular sections compile fine if I build as C++.
Unfortunately though, there are quite a few other areas that won't
compile as C++ (with MSVC).  So currently I can't build either as C or
C++.  Hope someone can help!

John
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

Emmanuele Bassi
Hi;

you should try the patch attached to this bug:

  https://bugzilla.gnome.org/show_bug.cgi?id=503096#c26

and see if it fixes the issue for you.

Ciao,
 Emmanuele.


On 2 November 2015 at 16:49, John Emmas <[hidden email]> wrote:

> Hi guys,
>
> I just updated from git master and noticed a problem when building with
> MSVC...
>
> Round about line 427, 'gtypes.h' has added a small section with some
> function definitions that look like this:-
>
>       static inline gboolean _GLIB_CHECKED_ADD_U32 (guint32 *dest, guint32
> a, guint32 b) {
>           *dest = a + b; return *dest >= a; }
>
> Unfortunately, MSVC won't compile the above if I try to compile as 'C' code.
> It compiles fine if I comment out the 'inline' keyword - but otherwise, I
> get the following compiler error for each of the newly added functions in
> that section:-
>
>       error C2054: expected '(' to follow 'inline'
>
> FWIW these particular sections compile fine if I build as C++. Unfortunately
> though, there are quite a few other areas that won't compile as C++ (with
> MSVC).  So currently I can't build either as C or C++.  Hope someone can
> help!
>
> John
> _______________________________________________
> gtk-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-devel-list



--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

John Emmas
In reply to this post by John Emmas
This is my third attempt to reply to Emmanuele so apologies if this comes through in duplicate (or even triplicate!!)  My posts to this list seem to frequently get lost somewhere (for some reason I've never understood).  Anyway, here's what I wrote...


On 02/11/2015 16:56, Emmanuele Bassi wrote:
you should try the patch attached to this bug:

https://bugzilla.gnome.org/show_bug.cgi?id=503096#c26

and see if it fixes the issue for you.


Thanks for the quick reply Emmanuele.

If you're referring to the problem with G_STATIC_ASSERT it's not relevant in my case because _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS doesn't seem to be defined anywhere.  However, if I explicitly #define it (and then apply the patch) that doesn't help.  I then just see the same error occur at line 417 instead of 427.

I've a strange feeling that we might need underscores here with MSVC 'C'.  The compiler seems happy with "_inline" and "__inline" - but "inline" is only accepted when building as C++.  I must admit, that comes as a bit of a surprise!!

John
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

Emmanuele Bassi
Hi;

On 2 November 2015 at 20:10, John Emmas <[hidden email]> wrote:

> This is my third attempt to reply to Emmanuele so apologies if this comes
> through in duplicate (or even triplicate!!)  My posts to this list seem to
> frequently get lost somewhere (for some reason I've never understood).
> Anyway, here's what I wrote...
>
>
> On 02/11/2015 16:56, Emmanuele Bassi wrote:
>
> you should try the patch attached to this bug:
>
>
> https://bugzilla.gnome.org/show_bug.cgi?id=503096#c26
>
>
> and see if it fixes the issue for you.
>
>
>
> Thanks for the quick reply Emmanuele.
>
> If you're referring to the problem with G_STATIC_ASSERT it's not relevant in
> my case because _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS doesn't seem to be
> defined anywhere.  However, if I explicitly #define it (and then apply the
> patch) that doesn't help.  I then just see the same error occur at line 417
> instead of 427.
>
> I've a strange feeling that we might need underscores here with MSVC 'C'.
> The compiler seems happy with "_inline" and "__inline" - but "inline" is
> only accepted when building as C++.  I must admit, that comes as a bit of a
> surprise!!

Indeed, given that GLib and GTK+ use inline all over the place — and
GLib requires support for static inline functions as part of the
toolchain requirements:

  https://wiki.gnome.org/Projects/GLib/CompilerRequirements

GLib has a bunch of macros to allow some sort of ABI compatibility
when using compilers that have different ideas about the inline
keyword, but that's just for legacy code.

Which version of MSVC are you using?

Ciao,
 Emmanuele.


--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

Arnavion
https://github.com/GNOME/glib/blob/236e804/glib/gutils.h#L69
Presumably this is not being included by gtypes.h

inline in C is a C99 feature, which is why older VS doesn't support
it. VS2015 does.

-Arnav

On Mon, Nov 2, 2015 at 2:27 PM, Emmanuele Bassi <[hidden email]> wrote:

> Hi;
>
> On 2 November 2015 at 20:10, John Emmas <[hidden email]> wrote:
>> This is my third attempt to reply to Emmanuele so apologies if this comes
>> through in duplicate (or even triplicate!!)  My posts to this list seem to
>> frequently get lost somewhere (for some reason I've never understood).
>> Anyway, here's what I wrote...
>>
>>
>> On 02/11/2015 16:56, Emmanuele Bassi wrote:
>>
>> you should try the patch attached to this bug:
>>
>>
>> https://bugzilla.gnome.org/show_bug.cgi?id=503096#c26
>>
>>
>> and see if it fixes the issue for you.
>>
>>
>>
>> Thanks for the quick reply Emmanuele.
>>
>> If you're referring to the problem with G_STATIC_ASSERT it's not relevant in
>> my case because _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS doesn't seem to be
>> defined anywhere.  However, if I explicitly #define it (and then apply the
>> patch) that doesn't help.  I then just see the same error occur at line 417
>> instead of 427.
>>
>> I've a strange feeling that we might need underscores here with MSVC 'C'.
>> The compiler seems happy with "_inline" and "__inline" - but "inline" is
>> only accepted when building as C++.  I must admit, that comes as a bit of a
>> surprise!!
>
> Indeed, given that GLib and GTK+ use inline all over the place — and
> GLib requires support for static inline functions as part of the
> toolchain requirements:
>
>   https://wiki.gnome.org/Projects/GLib/CompilerRequirements
>
> GLib has a bunch of macros to allow some sort of ABI compatibility
> when using compilers that have different ideas about the inline
> keyword, but that's just for legacy code.
>
> Which version of MSVC are you using?
>
> Ciao,
>  Emmanuele.
>
>
> --
> https://www.bassi.io
> [@] ebassi [@gmail.com]
> _______________________________________________
> gtk-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-devel-list
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

Emmanuele Bassi
Hi;

On 2 November 2015 at 22:50, Arnavion <[hidden email]> wrote:
> https://github.com/GNOME/glib/blob/236e804/glib/gutils.h#L69
> Presumably this is not being included by gtypes.h
>
> inline in C is a C99 feature, which is why older VS doesn't support
> it. VS2015 does.

I'm pretty sure MSVC versions prior to the one in Visual Studio 2015
support `static inline` function declarations.

Ciao,
 Emmanuele.

> -Arnav
>
> On Mon, Nov 2, 2015 at 2:27 PM, Emmanuele Bassi <[hidden email]> wrote:
>> Hi;
>>
>> On 2 November 2015 at 20:10, John Emmas <[hidden email]> wrote:
>>> This is my third attempt to reply to Emmanuele so apologies if this comes
>>> through in duplicate (or even triplicate!!)  My posts to this list seem to
>>> frequently get lost somewhere (for some reason I've never understood).
>>> Anyway, here's what I wrote...
>>>
>>>
>>> On 02/11/2015 16:56, Emmanuele Bassi wrote:
>>>
>>> you should try the patch attached to this bug:
>>>
>>>
>>> https://bugzilla.gnome.org/show_bug.cgi?id=503096#c26
>>>
>>>
>>> and see if it fixes the issue for you.
>>>
>>>
>>>
>>> Thanks for the quick reply Emmanuele.
>>>
>>> If you're referring to the problem with G_STATIC_ASSERT it's not relevant in
>>> my case because _GLIB_HAVE_BUILTIN_OVERFLOW_CHECKS doesn't seem to be
>>> defined anywhere.  However, if I explicitly #define it (and then apply the
>>> patch) that doesn't help.  I then just see the same error occur at line 417
>>> instead of 427.
>>>
>>> I've a strange feeling that we might need underscores here with MSVC 'C'.
>>> The compiler seems happy with "_inline" and "__inline" - but "inline" is
>>> only accepted when building as C++.  I must admit, that comes as a bit of a
>>> surprise!!
>>
>> Indeed, given that GLib and GTK+ use inline all over the place — and
>> GLib requires support for static inline functions as part of the
>> toolchain requirements:
>>
>>   https://wiki.gnome.org/Projects/GLib/CompilerRequirements
>>
>> GLib has a bunch of macros to allow some sort of ABI compatibility
>> when using compilers that have different ideas about the inline
>> keyword, but that's just for legacy code.
>>
>> Which version of MSVC are you using?
>>
>> Ciao,
>>  Emmanuele.
>>
>>
>> --
>> https://www.bassi.io
>> [@] ebassi [@gmail.com]
>> _______________________________________________
>> gtk-devel-list mailing list
>> [hidden email]
>> https://mail.gnome.org/mailman/listinfo/gtk-devel-list



--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

Tim-Philipp Müller
On Mon, 2015-11-02 at 23:20 +0000, Emmanuele Bassi wrote:

> > inline in C is a C99 feature, which is why older VS doesn't support
> > it. VS2015 does.
>
> I'm pretty sure MSVC versions prior to the one in Visual Studio 2015
> support `static inline` function declarations.

MS Visual C++ Express 2010 seems to want __inline instead of inline.

Apparently VS 2013 does too:
http://stackoverflow.com/questions/24736304/unable-to-use-inline-in-dec
laration-get-error-c2054

Which version did you have in mind?

 Cheers
  -Tim
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

John Emmas
In reply to this post by Arnavion
2nd attempt - sorry if this comes through twice...


On 02/11/2015 22:50, Arnavion wrote:
https://github.com/GNOME/glib/blob/236e804/glib/gutils.h#L69
Presumably this is not being included by gtypes.h


Yeah, that's true - and fixing it kinda works but it leaves a couple of problems...

1) Firstly, it needs to get #included quite a long way down (around line 95 of gtypes.h).  The reason for this is that the two headers have mutual dependencies - i.e. gutils.h needs some types which are defined in gtypes.h and vice versa.

2) Because of the above, some other source files are now fussy about which order we #include gtypes.h versus gutils.h

I think I'm reaching the conclusion that these new functions (_GLIB_CHECKED_ADD_U32 etc) have simply been placed in the wrong header file.  Maybe they need to be in gutils.h rather than gtypes.h?  I don't mind experimenting and moving them somewhere else temporarily if anyone can suggest a better location.  Thanks,

John
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

Simon McVittie-6
On 03/11/15 09:30, John Emmas wrote:

> On 02/11/2015 22:50, Arnavion wrote:
>> https://github.com/GNOME/glib/blob/236e804/glib/gutils.h#L69
>> Presumably this is not being included by gtypes.h
>
> 1) Firstly, it needs to get #included quite a long way down (around line
> 95 of gtypes.h).  The reason for this is that the two headers have
> mutual dependencies - i.e. gutils.h needs some types which are defined
> in gtypes.h and vice versa.
>
> 2) Because of the above, some other source files are now fussy about
> which order we #include gtypes.h versus gutils.h

Perhaps the "inline" stuff should move to gtypes.h, or somewhere even
lower-level, like glibconfig.h?

Or, given that
<https://wiki.gnome.org/Projects/GLib/CompilerRequirements> effectively
says that the old (non-C99) MSVC versions are not suitable compilers for
use with GLib, perhaps GLib should require that MSVC compilation is done
with something like

    cl.exe -Dinline=__inline

which *is* a suitable compiler?

    S
--
Simon McVittie
Collabora Ltd. <http://www.collabora.com/>

_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

John Emmas
On 3 Nov 2015, at 11:50, Simon McVittie wrote:

>
> Perhaps the "inline" stuff should move to gtypes.h, or somewhere even
> lower-level, like glibconfig.h?
>

As an experiment, I tried moving the inline stuff out of gutils.h and straight into gtypes.h (at line 391 - immediately before those newly added functions).  As far as MSVC was concerned it was perfectly happy - no other changes were needed.  But I guess there could (potentially) be knock-on effects for other compilers (unlikely perhaps - but non-msvc builds would definitely need to get tested).  Hopefully though, there wouldn't be any issues for user apps because the very first thing gutils.h does is to #include gtypes.h !!

This idea does seem like a good compromise to me and it does work for MSVC.  It'll get my vote if the other compilers are happy too.  I can produce a patch if anyone wants to test it with gcc etc.

John
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

Emmanuele Bassi
Hi;

On 3 November 2015 at 16:19, John Emmas <[hidden email]> wrote:

> On 3 Nov 2015, at 11:50, Simon McVittie wrote:
>
>>
>> Perhaps the "inline" stuff should move to gtypes.h, or somewhere even
>> lower-level, like glibconfig.h?
>>
>
> As an experiment, I tried moving the inline stuff out of gutils.h and straight into gtypes.h (at line 391 - immediately before those newly added functions).  As far as MSVC was concerned it was perfectly happy - no other changes were needed.  But I guess there could (potentially) be knock-on effects for other compilers (unlikely perhaps - but non-msvc builds would definitely need to get tested).  Hopefully though, there wouldn't be any issues for user apps because the very first thing gutils.h does is to #include gtypes.h !!
>
> This idea does seem like a good compromise to me and it does work for MSVC.  It'll get my vote if the other compilers are happy too.  I can produce a patch if anyone wants to test it with gcc etc.

Could you please leave a comment on the bug I linked to earlier in the
thread, detailing what you found?

Thanks!

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Broken 'C' compilation when building from Master with MSVC

John Emmas
On 5 Nov 2015, at 11:35, Emmanuele Bassi wrote:

>
> On 3 November 2015 at 16:19, John Emmas <[hidden email]> wrote:
>> As an experiment, I tried moving the inline stuff out of gutils.h and straight into gtypes.h (at line 391 - immediately before those newly added functions).  As far as MSVC was concerned it was perfectly happy - no other changes were needed.  [...]  I can produce a patch if anyone wants to test it with gcc etc.
>
> Could you please leave a comment on the bug I linked to earlier in the
> thread, detailing what you found?
>

Hi Emmanuele,

I just added a comment as well as attaching a patch in case anyone wants to test the non-msvc compilation.  Thanks.

John
_______________________________________________
gtk-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-devel-list