Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

c++ - Can g++ / minGW play nice with the Windows SDK? Is Visual Studio the only option?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...