#include 导致很多语法错误

2023-12-26

我的程序使用 Qt 和 OpenGL。它在 Linux 和 Mac 下都能正确编译。 在Windows上编译时,我需要#include windows.h才能使用OpenGL,代码如下,

#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64)
#include <windows.h>
#endif
#ifdef __APPLE__
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/glu.h>
#include <GL/glut.h>
#endif

但是,有很多错误消息,例如

 C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(167) : error C2146: syntax error : missing ')' before identifier 'PRPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(167) : error C2165: 'left-side modifier' : cannot modify pointers to data
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(167) : error C2513: 'void *' : no variable declared before '='
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(167) : error C2440: 'initializing' : cannot convert from 'std::ostream' to 'void *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(168) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(226) : error C2146: syntax error : missing ')' before identifier 'RPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(226) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(226) : error C2491: 'I_RpcNegotiateTransferSyntax' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(227) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(235) : error C2146: syntax error : missing ')' before identifier 'RPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(235) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(235) : error C2491: 'I_RpcGetBuffer' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(236) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(242) : error C2146: syntax error : missing ')' before identifier 'RPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(242) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(242) : error C2491: 'I_RpcGetBufferWithObject' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(244) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(251) : error C2146: syntax error : missing ')' before identifier 'RPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(251) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(251) : error C2491: 'I_RpcSendReceive' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(252) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(259) : error C2146: syntax error : missing ')' before identifier 'RPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(259) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(259) : error C2491: 'I_RpcFreeBuffer' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(260) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(267) : error C2146: syntax error : missing ')' before identifier 'PRPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(267) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(267) : error C2491: 'I_RpcSend' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(268) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(275) : error C2146: syntax error : missing ')' before identifier 'PRPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(275) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(275) : error C2491: 'I_RpcReceive' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(277) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(284) : error C2146: syntax error : missing ')' before identifier 'RPC_MESSAGE'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(284) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(284) : error C2491: 'I_RpcFreePipeBuffer' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(285) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(302) : error C2146: syntax error : missing ')' before identifier 'I_RPC_MUTEX'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(302) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(302) : error C2182: 'I_RpcRequestMutex' : illegal use of type 'void'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(302) : error C2491: 'I_RpcRequestMutex' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(303) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(438) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(453) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(479) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(487) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(534) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(542) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(728) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(744) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(754) : error C2146: syntax error : missing ')' before identifier 'UUID'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(754) : warning C4229: anachronism used : modifiers on data are ignored
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(754) : error C2491: 'I_UuidCreate' : definition of dllimport data not allowed
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(755) : error C2059: syntax error : ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(763) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(771) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(779) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(838) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(848) : error C2061: syntax error : identifier 'cout'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(873) : error C2144: syntax error : 'unsigned long' should be preceded by ')'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(873) : error C2448: 'I_RpcConnectionInqSockBuffSize' : function-style initializer appears to be a function definition
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(874) : error C2144: syntax error : 'unsigned long' should be preceded by ';'
C:\Program Files (x86)\Windows Kits\8.1\include\shared\rpcdcep.h(874) : fatal error C1903: unable to recover from previous error(s); stopping compilation

如果我不#include windows.h,那么这些错误将不会出现。 我正在使用 VS2013 和 Qt 5.3。


Microsoft Windows 上的 OpenGL 与 WGL 绑定,而 WGL 又与 GDI 绑定。

结果,你不能#include <gl/gl.h>(您通过包括来间接做到这一点<GL/glu.h>)而不首先包含一些定义 GDI/Windows 预处理器标记的特定于 Windows 的标头,例如WINGDIAPI and APIENTRY。但这实际上是 Windows 上的任何 OpenGL 程序与特定于 Windows 的任何内容(头文件方面)相关联的程度。

WinDef.h定义APIENTRY and WinGDI.h定义WINGDIAPI- 包括Windows.h引入了这两个标头(不幸的是还有很多其他垃圾)。所以包括Windows.h主要是为了方便;到最低限度地在 Windows 上编译 OpenGL 软件你应该#include <WinDef.h>其次是#include <WinGDI.h>然后最后#include <GL/gl.h>.

或者,您可以#define WIN32_LEAN_AND_MEAN就在之前#include <Windows.h>它将显著地减少通过包含该标头而引入的不相关事物的数量。许多 Visual C++ 项目实际上在首次创建时默认定义了预处理器定义,您可能想查看您的项目是否是这样配置的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

#include 导致很多语法错误 的相关文章

  • 在业务逻辑中使用反射是一种好的做法吗?

    我需要开发一个由两个主要部分组成的应用程序 具有特定业务类别的业务逻辑部分 例如书籍 图书馆 作者 一个通用部分 可以在数据网格中显示书籍 图书馆 将它们映射到数据库 通用部分使用反射从业务类中获取数据 而不需要在业务类中编写特定的数据网格
  • 使用 MingW 在 Windows 上传送 PyGObject/GTK+ 应用程序

    我在 Windows 上使用 PyGObject GTK 和 Python3 7 并且担心如何打包我的应用程序 借助Python官方生态系统 可以轻松使用冷冻机和venvs 然而 Windows 上的 PyGObject 和 GTK 需要
  • 使用 cout 打印字符数组的全部内容

    我对 C 很陌生 只是 Java 的背景不太好 并且对如何打印 char 数组的全部内容感到困惑 我相信我需要使用循环 并将循环基于数组的长度 但我的编译尝试没有成功 这就是我现在所拥有的 在此先感谢您的帮助 include
  • 从 QFile 获取句柄

    我有一个QFile 但我需要在其上调用一些仅接受HANDLE 有没有办法找回底层HANDLE of the QFile 我找到了一种使用的方法 get osfhandle 在 MinGW 和 VS 中可用 QFile file HANDLE
  • 多线程中的 OpenCV CascadeClassifier C++ 接口

    我想在多个线程中使用 CascadeClassifier 对象运行 OpenCV C 接口 我的程序的工作方式是我的主线程将 some file xml 加载到 CascadeClassifier 对象中 生成三个或更多线程并向它们传递级联
  • 虚拟调用与类型检查的另一个例子

    Problem 我发誓 每次我脑子里都在想 我应该使用虚拟调用而不是类型检查 例如 if obj is Foo else if obj is Bar 我想出了另一个例子 我不知道如何实现前者 我正在通过串行端口实现分组协议 一些伪代码可以最
  • Promise.defer 的正确模式是什么?

    我正在使用 TypeScript 和async await来表示异步工作流程 该工作流程的一部分是调用 Web Worker 并在其回调结果时继续 在 C 中 我会创建一个TaskCompletionSource await its Tas
  • 是否有在 std 容器中使用 unique_ptr 的透明方法?

    有没有透明的使用方式std unique ptr在容器中 include
  • 什么是 .NET 程序集?

    什么是 NET 程序集 我浏览了网络 但无法理解其定义 程序集是 net 应用程序的最小部署单元 它可以是一个dll or an exe 它主要有两种类型 私人集会 dll 或 exe 是一个应用程序的专有财产 一般存放在应用程序根文件夹中
  • 我可以调整移出的矢量的大小吗?

    我有一些代码 我想在其中绝对确保移出的代码std vector不会留下秘密数据 考虑加密密钥管理 在我的班级的移动构造函数中 我做了类似的事情 X X rhs secret vector std move rhs secret vector
  • 检查对象的每个属性是否为空

    我的课程具有多个属性 public class Employee public string TYPE get set public int SOURCE ID get set public string FIRST NAME get se
  • 带有 Null 的 Soap WSDL

    我需要在函数中指定一个可为空的参数 这不起作用
  • 如何在 .NET 中使 ComboBox 不可编辑?

    我想要一个 仅选择 ComboBox它提供了一个项目列表供用户选择 应在文本部分禁用打字ComboBox控制 我最初对此进行谷歌搜索 发现了一个过于复杂 误导性的建议来捕捉KeyPress event 要使 ComboBox 的文本部分不可
  • 如何让一段代码只执行一次?

    我有一个应用程序 其中有多种功能 每个函数都可以根据用户输入多次调用 但是 我只需要在函数中执行一小段代码一次 最初是在应用程序启动时执行 当稍后再次调用同一函数时 不得执行这段特定的代码 代码在VC 请告诉我处理这个问题最有效的方法 使用
  • 如何修改.NET Core中的文件访问控制

    我正在尝试更改 NET Core 中文件的权限 然而 似乎FileInfo https msdn microsoft com en us library system io fileinfo setaccesscontrol v vs 11
  • 如何从 Visual Studio 2012 导出 C# 应用程序以在其他计算机上运行?

    我刚刚在 Visual Studio 2012 中制作了我的第一个 C 应用程序 我想以某种方式导出它 以便其他人可以在他们的计算机 包括没有 Visual Studio 2012 的计算机 中使用它 我该怎么做 我是 C 新手 找不到任何
  • 使用DataContractSerializer进行序列化,但无法反序列化回来

    我有以下两个功能 public static string Serialize object obj DataContractSerializer serializer new DataContractSerializer obj GetT
  • 如何使用 C++20 std::format?

    C 20介绍std format 相比有哪些优势printf or std cout 我该如何使用它 有人给出了一个例子吗 与 printf 相比有哪些优点 类型安全 对于 printf 程序员必须仔细地将格式说明符与参数的类型相匹配 如果
  • 如何检查c#代码中死锁的可能性

    我的应用程序有时会停止在下面的代码中 并非总是如此 但有时会停止 全部3种方法CalcQuarterlyFigures CalcWeeklyFigures CalcMonthlyFigures return Task
  • WPF 媒体格式

    WPF 是否内置对任何音频和视频格式的支持 我将使用 MediaPlayer 和 MediaElement 类来构建一个小型媒体播放器 目前 我不想处理 NET 没有本机支持的编解码器和格式 WPF 默认支持视频格式 WMV MPEG 和一

随机推荐