3

我收到上述错误和大约 101 个其他错误(总共 102 个错误)。我四处搜索,发现的唯一解决方案是在 gl.h 之前包含 windows.h 库。但我已经在这样做了。那么解决方案是什么?谁能帮我?我正在使用过剩和opengl。以下是我的包含过程。如果您要求更多我的代码,请告诉我

#include <stdio.h>           // Standard C/C++ Input-Output
#include <math.h>            // Math Functions
#include <windows.h>        // Standard Header For MSWindows Applications
#include <GL/gl.h>        
#include <time.h>
#include <stdlib.h>
#include "SOIL.h"

这是完整的错误列表:

Error   1   error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error   2   error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error   3   error C2146: syntax error : missing ',' before identifier 'glAccum' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error   4   error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error   5   error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1152
Error   6   error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1153
Error   7   error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1153
Error   8   error C2146: syntax error : missing ',' before identifier 'glAlphaFunc' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1153
Error   9   error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1153
Error   10  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1153
Error   11  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1154
Error   12  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1154
Error   13  error C2146: syntax error : missing ',' before identifier 'glAreTexturesResident'   c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1154
Error   14  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1154
Error   15  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1154
Error   16  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1155
Error   17  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1155
Error   18  error C2146: syntax error : missing ',' before identifier 'glArrayElement'  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1155
Error   19  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1155
Error   20  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1155
Error   21  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1156
Error   22  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1156
Error   23  error C2146: syntax error : missing ',' before identifier 'glBegin' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1156
Error   24  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1156
Error   25  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1156
Error   26  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1157
Error   27  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1157
Error   28  error C2146: syntax error : missing ',' before identifier 'glBindTexture'   c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1157
Error   29  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1157
Error   30  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1157
Error   31  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1158
Error   32  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1158
Error   33  error C2146: syntax error : missing ',' before identifier 'glBitmap'    c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1158
Error   34  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1158
Error   35  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1158
Error   36  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1159
Error   37  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1159
Error   38  error C2146: syntax error : missing ',' before identifier 'glBlendFunc' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1159
Error   39  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1159
Error   40  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1159
Error   41  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1160
Error   42  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1160
Error   43  error C2146: syntax error : missing ',' before identifier 'glCallList'  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1160
Error   44  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1160
Error   45  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1160
Error   46  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1161
Error   47  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1161
Error   48  error C2146: syntax error : missing ',' before identifier 'glCallLists' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1161
Error   49  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1161
Error   50  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1161
Error   51  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1162
Error   52  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1162
Error   53  error C2146: syntax error : missing ',' before identifier 'glClear' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1162
Error   54  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1162
Error   55  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1162
Error   56  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1163
Error   57  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1163
Error   58  error C2146: syntax error : missing ',' before identifier 'glClearAccum'    c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1163
Error   59  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1163
Error   60  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1163
Error   61  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1164
Error   62  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1164
Error   63  error C2146: syntax error : missing ',' before identifier 'glClearColor'    c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1164
Error   64  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1164
Error   65  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1164
Error   66  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1165
Error   67  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1165
Error   68  error C2146: syntax error : missing ',' before identifier 'glClearDepth'    c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1165
Error   69  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1165
Error   70  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1165
Error   71  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1166
Error   72  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1166
Error   73  error C2146: syntax error : missing ',' before identifier 'glClearIndex'    c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1166
Error   74  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1166
Error   75  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1166
Error   76  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1167
Error   77  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1167
Error   78  error C2146: syntax error : missing ',' before identifier 'glClearStencil'  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1167
Error   79  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1167
Error   80  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1167
Error   81  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1168
Error   82  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1168
Error   83  error C2146: syntax error : missing ',' before identifier 'glClipPlane' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1168
Error   84  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1168
Error   85  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1168
Error   86  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1169
Error   87  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1169
Error   88  error C2146: syntax error : missing ',' before identifier 'glColor3b'   c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1169
Error   89  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1169
Error   90  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1169
Error   91  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1170
Error   92  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1170
Error   93  error C2146: syntax error : missing ',' before identifier 'glColor3bv'  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1170
Error   94  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1170
Error   95  error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1170
Error   96  error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1171
Error   97  error C2085: 'APIENTRY' : not in formal parameter list  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1171
Error   98  error C2146: syntax error : missing ',' before identifier 'glColor3d'   c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1171
Error   99  error C2143: syntax error : missing ';' before '('  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1171
Error   100 error C2059: syntax error : ')' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1171
Error   101 error C2054: expected '(' to follow 'WINGDIAPI' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1172
Error   102 error C1003: error count exceeds 100; stopping compilation  c:\program files (x86)\microsoft sdks\windows\v7.0a\include\gl\gl.h 1172
4

5 回答 5

7

这通常是由在编译设置中或在编译设置中定义引起WIN32_LEAN_AND_MEANstdafx.h

在包含之前定义该宏会windows.h自动排除不常用的头文件和定义。

由于您使用的是 OpenGL,因此您正在使用一些不常用的标头,因此您需要将其关闭。

它可能出现在诸如 stdafx.h 之类的标头中,如下所示:

#define WIN32_LEAN_AND_MEAN

或者它可能在编译设置中,如下所示:

-DWIN32_LEAN_AND_MEAN
于 2012-10-31T16:07:23.430 回答
5

您忘记在windows.h之前包含gl.h。来自http://www.opengl.org/archives/resources/faq/technical/gettingstarted.htm

Error:
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2054: expected '(' to
follow 'WINGDIAPI' 
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2085: 'APIENTRY' : not in
formal parameter list

没有#include windows.h 或在 gl.h 之后包含它。既不使用 GLUT 也不使用 MFC,但调用 OpenGL 的源文件应该:

     #include <windows.h> 
     #include <GL/gl.h>

为我工作。

另外,请确保您没有使用预编译的标头

于 2013-06-05T03:22:17.817 回答
2

好的,我遇到了同样的问题,我修复了它。只需确保您的项目中没有其他文件(预编译头文件/.c/.cpp)。删除它们并只留下您需要的文件,它会起作用

于 2013-10-07T06:01:19.480 回答
2

看来您正在使用 SOIL 库。确保包含 windows.h(预处理器可能采用不同的分支)。如果您不想更改 SOIL 库,请确保定义了 WIN32。如果没有,您可以将其替换为_WIN32。

于 2014-10-01T03:58:11.130 回答
0

这一切似乎都是错误的家伙(对不起!)。

仅仅因为这大声宣称需要包含 windows.h 并不意味着应该包含 windows.h。

OpenGL 是一个开放标准协议接口规范。因此,其相关的 STANDARD 标头(GL/gl.h、GL/glu.h 等)绝对不会因某些专有供应商设法提出的专有废话而造成大规模污染。

具体来说,我说的是可悲的 Win32 特定宏 WINGDIAPI 和 APIENTRY,它们已添加到以前的标准 GL 标头内容中(提示:请参阅该标头中的 SGI 文本),并导致这些 GL 标头不是正确独立的和通用接口了!!(即,需要大量的wingdi.h 和厨房水槽等,其后果是使用完全特定于环境的废话、windows.h 等在全球范围内污染您的整个源代码范围)

因此,要纠正这种可怕的情况,可能应该这样做:

  1. 创建特定用途的本地标头,尝试最精确地提供这些少数必需但缺少的(非独立标头!)环境特定部分:
  • APIENTRY 定义头文件
  • WINGDIAPI 定义头文件
  1. 通过在包含相关官方 GL 头(接口!)的任何地方包含这些帮助头来提供这些缺失的部分(由于非独立的 OpenGL 接口而损坏......) - 仅在 Windows 专有平台上(#ifdef _WIN32)!
  2. 非常注意将任何和所有 Windows 专有的转换到 OpenGL 的帮助程序(那些使用 Win32 HDC 等,例如 wgl*() API)处理到他们自己的严格隔离的翻译单元 (.cpp)
  3. 将所有标准/通用/跨平台/通用(阅读:无辜;-))OpenGL实现处理部分保留到它们自己的翻译单元(因此,完全不会被环境特定的windows.h废话感染,因此可以正常工作所有平台)
  4. 利润!(希望)

与主题相关的参考资料(可能已经有帮助):

github WindowsH模块化

话题相关的东西:

  • Win32 min / max 宏“命名空间”/符号污染(早期定义 NOMINMAX 并更喜欢在仍需要的地方使用 __min / __max)
  • Win32 近/远宏

事实仍然是,使用实际上是外来工具包的可忽略部分(在本例中为符号导出宏)污染标准的极简主义(?)接口(OpenGL)是非常侵入性的行为,因此需要充分(标题端!)具有完全特定于环境的废话的所谓通用用户代码的全局范围污染:windows.h(而不是简单地确保这些公共接口头文件已经在范围内提供了自己的编译器特定符号导出宏)。

tl;dr:“一个平台启用,十一个平台损坏 - 工作完成”

于 2019-11-11T15:47:34.437 回答