g++ / minGW 可以很好地与 Windows SDK 配合使用吗?Visual Studio 是唯一的选择吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2022112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can g++ / minGW play nice with the Windows SDK? Is Visual Studio the only option?
提问by AndyL
Can g++ and minGW on Windows XP use the Windows SDK?
Windows XP 上的 g++ 和 minGW 可以使用 Windows SDK 吗?
Specifically, why does g++ fail to compile:
具体来说,为什么g++编译失败:
#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
我已经安装了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 grabberthat has an SDK which was designed for Visual Studio. The framegrabber SDK depends on header files from the Windows SDK.
我正在开发一个大型实时图像处理软件项目,该项目迄今为止一直使用 g++、minGW 和 gnu make 文件(手工编写)。对于新功能,我需要与具有专为 Visual Studio 设计的SDK的帧采集器连接。framegrabber SDK 依赖于来自 Windows SDK 的头文件。
Do I need to learn Visual Studio or is there another way?
我需要学习 Visual Studio 还是有其他方法?
采纳答案by AndyL
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.
我每天都使用 MinGW 编译 Windows 程序,问题为零。您的安装肯定有问题 - 试试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 -mwindowsflag. I just compiled your program using MinGW (TDM build) g++ 4.4.1, with the command line:
编辑:只需重新阅读您的帖子 - 您不需要在执行时指定包含目录,并且可能不应该这样做。此外,您可能(或可能不需要)需要稍微神秘的-mwindows标志。我刚刚使用 MinGW (TDM build) g++ 4.4.1 和命令行编译了你的程序:
g++ main.cpp
with absolutely no problems.
绝对没有问题。
More Info:Just so you know what the -mwindowsflag does, the GCC docs say:
更多信息:为了让您知道-mwindows标志的作用,GCC 文档说:
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.
此选项可用于 Cygwin 和 MinGW 目标。它指定将通过指示链接器适当设置 PE 标头子系统类型来生成 GUI 应用程序。
Personally, I've never found it necessary, but then my Windows apps are all command line tools or servers.
就我个人而言,我从来没有觉得有必要,但是我的 Windows 应用程序都是命令行工具或服务器。
回答by XP1
According to the discussions from the MinGW-users mailing list, you might encounter compatibility problems with the Windows SDK, and you may have to fix those problems yourself.
根据 MinGW-users 邮件列表中的讨论,您可能会遇到与 Windows SDK 的兼容性问题,您可能必须自己解决这些问题。
Georgi Petrov [Dec 27, 2010; 8:33am]:
乔治·彼得罗夫 [2010 年 12 月 27 日;上午 8 点 33 分]:
Hello,
I'm trying to develop a EVR (Vista/7 specific video presentation API) renderer for MPlayer on MSYS/MinGW. The problem is that I have Windows SDK v7.1 and I need evr.h from it. If I try to copy it to MinGW's include directory as well as the 12 header files it includes, the compilation is close to impossible. I have a TON of errors just by including evr.h, nothing else. I investigated and found that I can't use the Windows SDK header files directly with MinGW, because it ships with its own header files, which are sometimes very, very different.The problem is that Media Foundation/Enhanced Video Renderer header files are not part of MinGW's header files.
What should I do?
你好,
我正在尝试为 MSYS/MinGW 上的 MPlayer 开发 EVR(Vista/7 特定视频演示 API)渲染器。问题是我有 Windows SDK v7.1,我需要它的 evr.h。如果我尝试将它复制到 MinGW 的包含目录以及它包含的 12 个头文件,编译几乎是不可能的。仅通过包含 evr.h,我就有大量错误,仅此而已。我调查并发现我不能直接将 Windows SDK 头文件与 MinGW 一起使用,因为它附带了自己的头文件,这些头文件有时非常非常不同。问题是 Media Foundation/Enhanced Video Renderer 头文件不是 MinGW 头文件的一部分。
我该怎么办?
Windows SDK header files question:
http://mingw-users.1079350.n2.nabble.com/Windows-SDK-header-files-question-td5870336.html
Windows SDK 头文件问题:
http://mingw-users.1079350.n2.nabble.com/Windows-SDK-header-files-question-td5870336.html
Ross Ridge [Oct 10, 2010; 10:16pm]:
罗斯岭 [2010 年 10 月 10 日;晚上 10:16]:
For the most part the Windows SDK headers aren't incompatible with GCC. If there one particular header file you need that doesn't exist in win32api heapers or is missing something you need, then you can try just using that one header with from the Windows SDK and use win32api for the rest.
It's also possible to only use Windows SDK headers, and avoid using the win32api headers entirely, but you need to fix a number of problems in key header files. I used to just modify the headers, but the Windows SDK has actually gotten a bit more compatible and now I use wrappers to fix the problems.
There are some header files and libraries that are pretty much fundementally incompatible with GCC, like GDI+. If you want to use GDI+, you'll need to use a Microsoft compiler.
Ross Ridge
大多数情况下,Windows SDK 标头与 GCC 并不兼容。如果您需要的某个特定头文件在 win32api 堆中不存在或缺少您需要的某些内容,那么您可以尝试仅使用 Windows SDK 中的该头文件,其余使用 win32api。
也可以只使用 Windows SDK 头文件,而完全避免使用 win32api 头文件,但您需要修复关键头文件中的一些问题。我以前只是修改头文件,但实际上 Windows SDK 的兼容性更好了,现在我使用包装器来解决问题。
有一些头文件和库在根本上与 GCC 不兼容,例如 GDI+。如果要使用 GDI+,则需要使用 Microsoft 编译器。
Ross Ridge
compiling against Windows SDK:
http://mingw-users.1079350.n2.nabble.com/compiling-against-Windows-SDK-td5609389.html
回答by smerlin
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 ?!)
编辑:我的 gcc 编译您的脚本也没有问题(并且没有这些定义)。我正在使用 mingw 的 gcc 4.40 (alpha ?!)