0

我制作了一个可与 GCC(4.7.3 及更高版本)编译并在 Linux 上运行的 OpenGL 项目。当尝试在 Windows 下使用安装了 GCC 4.9.2 的 MSYS2 编译相同的代码时,我收到大量错误报告:

g++ -g --std=c++11 src/*.cpp -Iinclude -Isrc -lIL -lILU -lILUT -lGL -lGLU -lglut -lm -DWIN32 -I/mingw64/include windows/src/*.cpp -o "Achtung, die Kurve 3D!"
In file included from /usr/lib/gcc/x86_64-pc-msys/4.9.2/include/c++/bits/stringfwd.h:40:0,
                 from /usr/lib/gcc/x86_64-pc-msys/4.9.2/include/c++/string:39,
                 from include/windows.h:1,
                 from /usr/include/w32api/GL/gl.h:13,
                 from /mingw64/include/GL/freeglut_std.h:143,
                 from /mingw64/include/GL/freeglut.h:17,
                 from src/controls.cpp:1:
/usr/lib/gcc/x86_64-pc-msys/4.9.2/include/c++/bits/memoryfwd.h:63:3: error: template with C linkage
   template<typename>
   ^
/usr/lib/gcc/x86_64-pc-msys/4.9.2/include/c++/bits/memoryfwd.h:66:3: error: template specialization with C linkage
   template<>
   ^
/usr/lib/gcc/x86_64-pc-msys/4.9.2/include/c++/bits/memoryfwd.h:70:3: error: template with C linkage
   template<typename, typename>
   ^

...

In file included from /mingw64/include/GL/freeglut_std.h:143:0,
                 from /mingw64/include/GL/freeglut.h:17,
                 from src/controls.cpp:1:
/usr/include/w32api/GL/gl.h:684:1: error: ‘WINGDIAPI’ does not name a type
 WINGDIAPI void APIENTRY glAccum(GLenum op,GLfloat value);

...

/usr/include/w32api/GL/gl.h:1037:24: error: expected ‘)’ before ‘*’ token
 typedef void (APIENTRY *PFNGLGETCOLORTABLEPARAMETERFVEXTPROC)(GLenum target,GLenum pname,GLfloat *params);
                        ^
In file included from /mingw64/include/GL/freeglut_std.h:144:0,
                 from /mingw64/include/GL/freeglut.h:17,
                 from src/controls.cpp:1:
/usr/include/w32api/GL/glu.h:24:25: error: expected initializer before ‘gluErrorString’
 const GLubyte *APIENTRY gluErrorString(GLenum errCode);
                         ^
/usr/include/w32api/GL/glu.h:25:25: error: expected initializer before ‘gluErrorUnicodeStringEXT’
 const wchar_t *APIENTRY gluErrorUnicodeStringEXT(GLenum errCode);
                         ^

...

这仅取自包含 4500 行错误的部分日志。这些是重复多次的最常见的。

我以前认为问题出在旧的 MSYS/MinGW(不是 MSYS2 端口)上,我首先尝试了相同的结果。然而,MSYS2 并没有解决让我完全不知所措的问题,因为我的代码是用 C++ 编写的,它只需要标准的 C 和 C++ 头文件以及一些 GL 头文件。我不使用任何外部“C”修饰。

4

2 回答 2

1

您在这里使用的是 msys2 GCC,而不是 mingw-w64 GCC。

请阅读 MSYS2 wiki [1],其中解释了所有这些,但简要说明:

运行mingw64_shell.bat,而不是msys2_shell.bat安装 mingw-w64 GCC 工具链包。此命令使用 bash 花括号扩展功能安装 32 位和 64 位:

pacman -S mingw-w64-{x86_64,i686}-toolchain

..然后看到gcc -dumpmachine报告x86_64-w64-mingw32而不是x86_64-pc-msys

[1] https://sourceforge.net/p/msys2/wiki/Home/

于 2015-04-26T22:00:01.357 回答
0

结果证明该问题与 OpenGL 无关,也与 MSYS(2)/MinGW(-w64) 或 MS Visual Studio 2013 无关。

对于可能遇到与我相同的问题的任何人,绝大多数错误报告都是生成的,因为windows.h我的项目的包含路径中存在一个自定义头文件。具有相同名称的标头存在于标准 Windows 标头库中,并且对于其他库的正常功能至关重要。

经验教训:永远不要试图在操作系统之后使用特定于系统的代码来命名文件。

于 2015-04-28T17:42:28.260 回答