MinGW doesn't compile windows.h

Hello,
I'm trying to compile the "windows.h" Header file with MinGW on my Windows 8.1 64-Bit Computer.
According to the MinGW Installation Manager the Windows32api is installed, so it should be working.

The problem is, that the files are found but can't be compiled right, as you can see below.

What do I have to change to get the windows.h Headers to be compiled right?

Thanks for your help.

main.cpp
1
2
3
4
5
6
7
8
#include <windows.h>


int main() {

	return 0;
}


makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
EXEC = main.exe					# The final executable that is created sould be named main.exe (store "main.exe" in EXEC)
SOURCES = $(wildcard *.cpp)		# Store the names of all cpp files in the current filder in SOURCES
HEADERS = $(wildcard *.h*)
OBJECTS = $(SOURCES:.cpp=.o)	# Replace the .cpp in all filenames in SOURCES by .o and store this in OBJECTS

# Make file rules have the following syntax:
# ToDo: Preconditions
#	Intended lines contain program calls that create
#	ToDo from Preconditions

all: $(EXEC)					# To build the all target (happens when "make all" is called), make has to build main.exe

main.exe: $(OBJECTS)			# To build main.exe, make has to build all object files
	g++ -v $(OBJECTS) -o $(EXEC) `pkg-config gtkmm-2.4 --libs` # This line tells make what to do if the object files are available

%.o: %.cpp $(HEADERS)			# To build an .o file, the corresponding .cpp file has to be available
	g++ -c -v -O3 `pkg-config gtkmm-2.4 --cflags` $< -o $@	# This line tells make what to do if the cpp files are available

clean:							# To build the clean target (happens when "make clean" is called), no preconditions are necessary
	rm -f $(EXEC) $(OBJECTS)	# For cleaning, the main.exe file as well as the .o files will be deleted
	
	

Output:

15:26:00 **** Build of configuration Default for project WinTest ****
make all 
g++ -c -v -O3 `pkg-config gtkmm-2.4 --cflags` main.cpp -o main.o	# This line tells make what to do if the cpp files are available
Using built-in specs.
COLLECT_GCC=c:\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp
 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC) 
COLLECT_GCC_OPTIONS='-c' '-v' '-O3' '-mms-bitfields' '-I' 

...
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:901:2: error: 'LPDEVMODE' does not name a type
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:904:2: error: 'LPDEVMODE' does not name a type
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:914:27: error: typedef '__AW' is initialized (use decltype instead)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:914:14: error: 'DRIVER_INFO_4' was not declared in this scope
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:915:27: error: typedef '__AW' is initialized (use decltype instead)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:915:14: error: 'DRIVER_INFO_5' was not declared in this scope
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:916:27: error: typedef '__AW' is initialized (use decltype instead)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:916:14: error: 'DRIVER_INFO_6' was not declared in this scope
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:917:33: error: typedef '__AW' is initialized (use decltype instead)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:917:14: error: 'PRINTER_ENUM_VALUES' was not declared in this scope
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:918:28: error: typedef '__AW' is initialized (use decltype instead)
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/winspool.h:918:14: error: 'PRINTER_INFO_7' was not declared in this scope
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/objbase.h:95:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/ole2.h:31,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/windows.h:101,
                 from main.cpp:7:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/objidl.h:633:2: error: 'GetObject' has not been declared
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/objidl.h:633:51: error: '__AW' declared as function returning a function
In file included from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/ole2.h:52:0,
                 from c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/windows.h:101,
                 from main.cpp:7:
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/oleidl.h:157:2: error: 'GetObject' has not been declared
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/oleidl.h:157:69: error: '__AW' declared as function returning a function
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/oleidl.h:322:2: error: 'TranslateAccelerator' has not been declared
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/oleidl.h:322:47: error: '__AW' declared as function returning a function
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/oleidl.h:348:2: error: 'TranslateAccelerator' has not been declared
c:\mingw\bin\../lib/gcc/mingw32/4.6.2/../../../../include/oleidl.h:348:52: error: '__AW' declared as function returning a function
make: *** [main.o] Error 1

15:26:05 Build Finished (took 5s.587ms)


Why don't you compile from the command line?
Open CMD then type cd PATH_TO_YOUR_MAIN.CPP_FILE'S_FOLDER then type g++ -o main.exe main.cpp
Last edited on
Thanks for your fast advice.
I just tried to complie from the command line, but I get the same output.
Last edited on
Hmm that code you gave compiles fine for me ;o.

Try compiling this code:
1
2
3
4
5
6
7
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
{
    MessageBox(NULL, "OK So this is working!", "Msg LOL", MB_OK);
    return 0;
}


If it compiles correctly and if you run the .exe generated you should see a Message box.
Still the same output.
Well I see that you are using an old version of MinGW - v4.6.2. Why don't you get the latest 64bit version?

First uninstall the current installation.

Then go and download this:
http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-4.8.1-3.exe/download

Then install it (Takes <= 1 min).

Your current installation probably have some problems.
Wow, so easy. It's working now. Thank you very much :)
Topic archived. No new replies allowed.