GNOME Bugzilla – Bug 774325
MinGW: <windows.h> is missing in gtksourceview-init.c
Last modified: 2016-12-05 19:28:09 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, ^
Thanks, pushed as commit 6dc6c0bf09f54c91788f648b543f76c97820156b. And backported on 3.24 and 3.22.
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.
I confirmed that gtksourceview can be built with "#include <windef.h>" and MinGW.
(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?
Could you show the error messages you got?
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):
+ Trace 236914
sys.exit(scanner_main(sys.argv))
shlibs = create_binary(transformer, options, args)
gdump_parser.get_error_quark_functions())
return dc.run()
introspection_obj = self._compile(c_path)
self._options.init_sections)
source_str.rfind(os.sep)]))
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
raise CompileError, msg
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
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!
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.
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
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).
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
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... :(
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.