After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 774325 - MinGW: <windows.h> is missing in gtksourceview-init.c
MinGW: <windows.h> is missing in gtksourceview-init.c
Status: RESOLVED FIXED
Product: gtksourceview
Classification: Platform
Component: General
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: GTK Sourceview maintainers
GTK Sourceview maintainers
Depends on:
Blocks:
 
 
Reported: 2016-11-12 14:56 UTC by Kouhei Sutou
Modified: 2016-12-05 19:28 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fix the problem (678 bytes, patch)
2016-11-12 14:56 UTC, Kouhei Sutou
none Details | Review

Description Kouhei Sutou 2016-11-12 14:56:36 UTC
Created attachment 339694 [details] [review]
Fix the problem

gtksourceview-init.c uses HMODULE. <windows.h> is required to use it with MinGW.

Here is error message from GCC:



gtksourceview-init.c:40:8: error: unknown type name 'HMODULE'
 static HMODULE gtksourceview_dll;
        ^
gtksourceview-init.c: At top level:
gtksourceview-init.c:150:1: error: unknown type name 'BOOL'
 BOOL WINAPI DllMain (HINSTANCE hinstDLL,
 ^
gtksourceview-init.c:150:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'DllMain'
 BOOL WINAPI DllMain (HINSTANCE hinstDLL,
             ^
gtksourceview-init.c:154:1: error: unknown type name 'BOOL'
 BOOL WINAPI
 ^
gtksourceview-init.c:155:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'DllMain'
 DllMain (HINSTANCE hinstDLL,
 ^
Comment 1 Sébastien Wilmet 2016-11-12 15:49:29 UTC
Thanks, pushed as commit 6dc6c0bf09f54c91788f648b543f76c97820156b.
And backported on 3.24 and 3.22.
Comment 2 Sébastien Wilmet 2016-12-02 12:23:02 UTC
Apparently this didn't work with msys2, see this commit:
https://git.gnome.org/browse/gtksourceview/commit/?id=71924eebd1d7456a12d8dff24faf81b4950c1d87

Now it is:
> #include <windef.h>

In other modules it is:
> #define WIN32_LEAN_AND_MEAN
> #include <windows.h>

Does it work in all cases with windef.h? Can you test with MinGW? Thanks.
Comment 3 Kouhei Sutou 2016-12-02 14:48:11 UTC
I confirmed that gtksourceview can be built with "#include <windef.h>" and MinGW.
Comment 4 Ignacio Casal Quinteiro (nacho) 2016-12-02 14:55:12 UTC
(In reply to Kouhei Sutou from comment #3)
> I confirmed that gtksourceview can be built with "#include <windef.h>" and
> MinGW.

Here now it fails when trying to build the introspection stuff. Does it work for you?
Comment 5 Kouhei Sutou 2016-12-03 01:00:55 UTC
Could you show the error messages you got?
Comment 6 Ignacio Casal Quinteiro (nacho) 2016-12-03 20:04:08 UTC
Here it is what I am currently getting:

make[4]: Entering directory '/home/nacho/MINGW-packages/mingw-w64-gtksourceview3/src/build-x86_64-w64-mingw32/gtksourceview'
CPPFLAGS="-D_FORTIFY_SOURCE=2 -D__USE_MINGW_ANSI_STDIO=1 -I/mingw64/include" CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe" LDFLAGS="-pipe" CC="x86_64-w64-mingw32-gcc" CC="x86_64-w64-mingw32-gcc" C:/msys64/mingw64/bin/g-ir-scanner  -I../../gtksourceview-3.22.2 -I.. --c-include=gtksourceview/gtksource.h --warn-all --namespace=GtkSource --nsversion=3.0 --libtool="/bin/sh ../libtool" --pkg=gtk+-3.0 --pkg=gdk-3.0 --include=Gtk-3.0 --include=Gdk-3.0 --pkg-export=gtksourceview-3.0  --library=libgtksourceview-3.0.la --warn-all                                                              --cflags-begin -mms-bitfields -pthread -mms-bitfields -IC:/msys64/mingw64/include/gtk-3.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/pango-1.0 -IC:/msys64/mingw64/include/atk-1.0 -IC:/msys64/mingw64/include/cairo -IC:/msys64/mingw64/include/pixman-1 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/freetype2 -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/harfbuzz -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/gdk-pixbuf-2.0 -IC:/msys64/mingw64/include/libpng16 -IC:/msys64/mingw64/include/glib-2.0 -IC:/msys64/mingw64/lib/glib-2.0/include -IC:/msys64/mingw64/include -IC:/msys64/mingw64/include/libxml2 --cflags-end  --argfile=GtkSource-3.0.gir.files --output GtkSource-3.0.gir
Assembler messages:
Fatal error: can't create tmp-introspectvxfgkb/msys64/home/nacho/MINGW-packages/mingw-w64-gtksourceview3/src/build-x86_64-w64-mingw32/gtksourceview/tmp-introspectvxfgkb/GtkSource-3.0.o: No such file or directory
C:/msys64/home/nacho/MINGW-packages/mingw-w64-gtksourceview3/src/build-x86_64-w64-mingw32/gtksourceview/tmp-introspectvxfgkb/GtkSource-3.0.c:726:1: fatal error: error writing to -: Invalid argument
 };
 ^
compilation terminated.
Traceback (most recent call last):
  • File "C:/msys64/mingw64/bin/g-ir-scanner", line 66 in <module>
    sys.exit(scanner_main(sys.argv))
  • File "C:/msys64/mingw64/bin/../lib/gobject-introspection/giscanner/scannermain.py", line 545 in scanner_main
    shlibs = create_binary(transformer, options, args)
  • File "C:/msys64/mingw64/bin/../lib/gobject-introspection/giscanner/scannermain.py", line 419 in create_binary
    gdump_parser.get_error_quark_functions())
  • File "C:/msys64/mingw64/bin/../lib/gobject-introspection/giscanner/dumper.py", line 328 in compile_introspection_binary
    return dc.run()
  • File "C:/msys64/mingw64/bin/../lib/gobject-introspection/giscanner/dumper.py", line 167 in run
    introspection_obj = self._compile(c_path)
  • File "C:/msys64/mingw64/bin/../lib/gobject-introspection/giscanner/dumper.py", line 207 in _compile
    self._options.init_sections)
  • File "C:/msys64/mingw64/bin/../lib/gobject-introspection/giscanner/ccompiler.py", line 241 in compile
    source_str.rfind(os.sep)]))
  • File "C:/msys64/mingw64/lib/python2.7/distutils/ccompiler.py", line 574 in compile
    self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
  • File "C:/msys64/mingw64/lib/python2.7/distutils/cygwinccompiler.py", line 189 in _compile
    raise CompileError, msg
distutils.errors.CompileError: command 'C:\\msys64\\mingw64\\bin/x86_64-w64-mingw32-gcc.exe' failed with exit status 1
make[4]: *** [C:/msys64/mingw64/share/gobject-introspection-1.0/Makefile.introspection:174: GtkSource-3.0.gir] Error 1
make[4]: Leaving directory '/home/nacho/MINGW-packages/mingw-w64-gtksourceview3/src/build-x86_64-w64-mingw32/gtksourceview'
make[3]: *** [Makefile:1652: all-recursive] Error 1
make[3]: Leaving directory '/home/nacho/MINGW-packages/mingw-w64-gtksourceview3/src/build-x86_64-w64-mingw32/gtksourceview'
make[2]: *** [Makefile:961: all] Error 2
make[2]: Leaving directory '/home/nacho/MINGW-packages/mingw-w64-gtksourceview3/src/build-x86_64-w64-mingw32/gtksourceview'
make[1]: *** [Makefile:647: all-recursive] Error 1
make[1]: Leaving directory '/home/nacho/MINGW-packages/mingw-w64-gtksourceview3/src/build-x86_64-w64-mingw32'
make: *** [Makefile:554: all] Error 2
Comment 7 Fan, Chun-wei 2016-12-04 03:38:54 UTC
Hi,

I don't think one is normally supposed to include windef.h directly (normally MSDN tells you to include windows.h to include this header).  The WIN32_LEAN_AND_MEAN is used to reduce the amount of baggage that is included when one includes windows.h.

So I would define that macro, then include windows.h, at least from an msvc point of view.

With blessings, and cheers!
Comment 8 Kouhei Sutou 2016-12-04 14:39:29 UTC
Thanks for sharing error message.
It seems that you're using MSYS2. I'm using MinGW on Linux (cross compile). So I can't help you. Sorry.

Sébastien Wilmet said this change fixes build failure on MSYS2 at Comment #2. So he may help you.
Comment 9 LRN 2016-12-04 15:35:04 UTC
gtksourceview-3.99.2 compiled for me just fine[1] in my[2] MSYS2, and gtksourceview-3.99.2 with commit 71924eebd1d7456a12d8dff24faf81b4950c1d87 applied on top of it also compiled just fine.

[1] I also needed to remove -DDATADIR=\""$(datadir)"\" from AM_CPPFLAGS in two places, but that is just to compensate for local MSYS2 quirks.

[2] which is slightly different from stock MSYS2
Comment 10 Sébastien Wilmet 2016-12-04 17:06:04 UTC
So I think the best is:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

If it works for everybody.

That's what libsoup uses:
https://git.gnome.org/browse/libsoup/tree/libsoup/soup-init.c

I've originally copied the code from libsoup to gspell, and then copied from gspell to GtkSourceView (and forgot the #include along the way since in gspell it was included in the .h file).
Comment 11 Ignacio Casal Quinteiro (nacho) 2016-12-04 18:25:17 UTC
I just tested it and it works for me with the define so I would say to change it to:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

LRN: still getting that problem with 3.22.2 + this change ^^ with stock msys2
Comment 12 Ignacio Casal Quinteiro (nacho) 2016-12-04 18:32:56 UTC
I just tested 3.99.2 and I still have the same problem with introspection. I guess it could be some problem on my copy of msys2... :(
Comment 13 Sébastien Wilmet 2016-12-05 19:28:09 UTC
Pushed commit 39e66445a96181c27f3a5d833fc72aa252ec3f5b to do:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

Cherry-picked on the gnome-3-24 and gnome-3-22 branches.

Let's close the bug, feel free to reopen if there is still a problem.