views:

1119

answers:

4

Can g++ and minGW on Windows XP use the Windows SDK?

Specifically, why does g++ fail to compile:

#include <stdio.h>
#include <windows.h>

int main(void) {
 printf("!!!Hello World!!!");
 return EXIT_SUCCESS;
}

I have tried compiling by by running:

g++ -c -Wall  Test.cpp -IC:/Program\ Files/Microsoft\ Platform\ SDK/Include/

I get a litany of compile errors beginning with

winnt.h:666:2: #error Must define a target architecture.

I have installed the Windows Server 2003 SP1 Platform SDK

Background

I am working on a large real-time image processing software project that up until now has used g++, minGW and gnu make files (written by hand). For a new feature, I need to interface with a frame grabber that has an SDK which was designed for Visual Studio. The framegrabber SDK depends on header files from the Windows SDK.

Do I need to learn Visual Studio or is there another way?

+4  A: 

I use MinGW to compile Windows programs every day, with zero problems. There must be something wrong with your installation - try the version at Twilight Dragon Media.

Edit: Just re-read your post - you do not need to specify the include directory as you are doing, and probably should not do so. Also, you may (or may not) need the slightly mysterious -mwindows flag. I just compiled your program using MinGW (TDM build) g++ 4.4.1, with the command line:

g++ main.cpp

with absolutely no problems.

More Info: Just so you know what the -mwindows flag does, the GCC docs say:

This option is available for Cygwin and MinGW targets.It specifes that a GUI application is to be generated by instructing the linker to set the PE header subsystem type appropriately.

Personally, I've never found it necessary, but then my Windows apps are all command line tools or servers.

anon
-mwindows does the trick! Thanks!
AndyL
Why do you not need to specify the include directory? How does g++ know where the include files are? For example, when I include my framegrabber SDK my compiler complains that it can't find a crtDbg.h include file. That header file exists in C:\Program Files\Microsoft Platform SDK\Include\crt\ but g++ doesn't seem to know about it.
AndyL
MinGW GCC picks up the include files from its own include directory, which contains its own versions of the windows headers. If you need to specify a "non-standard" header then you may need to use the include path, but you should make sure it comes after the GCC default path. Also, you need to be a bit careful with the case of filenames if you want to write portable code - you should never use mixed case.
anon
I see. Thanks. What is the order of precedence for including paths? Does a "-I" passed to the compiler override the GCC default path?
AndyL
Also, if you want a happy life, install any extra headers and libraries in a path without any spaces in the directory names. Remember GCC is a UNIX based tool chain, and UNIX users almost never create file names with spaces in them, so the tools have not been well tested on such names.
anon
Can't remember what the precedence is - the GCC manual is available at http://gcc.gnu.org/onlinedocs.
anon
A: 

try adding these defines before you include those windows headers

#define WINVER 0x0501
#define _WIN32_WINNT 0x0501

EDIT: my gcc compiles your script without problems (and without these defines) aswell. I am using mingw's gcc 4.40 (alpha ?!)

smerlin
There is absolutely no need to do this.
anon
A: 

What should I do, when I want exactly those header files from Windows SDK and not any others? There is a shitload of compiler errors when I try this. I just don't like bloated programs with unnecessary code. Did you ever compare two programs - one compiled with MinGW compiler/headers - and one with MS Visual Studio Compiler/Windows SDK headers? A small "Hello world!" program - the difference is about 300kb! I just can't overlook this.

I tried with both - MinGW and CygWin.

spammer70
A: 

Andy have you meanwile got a solution for this issue? I actually run in the same problems using MinGW/MSYS in handshake with the Windows SDK.

I've to develop a win32 plattform migration of a stacktrace walk mechanism which allready works fine on Linux OS.

First i've tried to implement a stackwalk using the win32 CaptureStackBackTrace API mechanism. But this method is not integrated in the actually winbase header of mingw... So i decided tried use the dbgheader mechanism ... But i fail again, because the dbghelp header and libraries are not part of the MinGW installation...

Now i try to use MinGW/MSYS in handshake with the actually Widnows SDK...

I would be grateful for any information. Best regards, Chris

Hellhound
Well for me, the mysterious -mwindows flag solved my problem at the time. Don't know if that will help you. Maybe try asking your own question and provide more details and specifics?
AndyL
ah.. just found your question at http://stackoverflow.com/questions/3318564/win32-api-stack-walk-with-mingw-msys ... good luck..
AndyL