0

I have made an OpenGL project compilable with GCC (version 4.7.3 and newer) and runable on Linux. When trying to compile the same code under Windows using MSYS2 with GCC 4.9.2 installed, I get tons of error reports:

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);
                         ^

...

This is taken from just a partial log consisting of 4500 lines of errors. These are the most frequent ones repeated many times.

I previously thought that the problem lied in old MSYS/MinGW (not the MSYS2 port) which I tried first with the same results. However, MSYS2 did not solve the problems which makes me completely clueless since my code is written in C++ and it only requires standard C and C++ header files along with some GL ones. I do not use any extern "C" mangling.

Kyselejsyreček
  • 459
  • 1
  • 3
  • 16

2 Answers2

1

You are using msys2 GCC here, not mingw-w64 GCC.

Please read the MSYS2 wiki [1] where all of this is explained, but briefly:

Run mingw64_shell.bat, not msys2_shell.bat, install the mingw-w64 GCC toolchain package(s). This command installs both the 32-bit and 64-bit ones using the bash curly brace expansion feature:

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

.. then see that gcc -dumpmachine reports x86_64-w64-mingw32 and not x86_64-pc-msys

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

Ray Donnelly
  • 3,920
  • 1
  • 19
  • 20
  • Thank you for your help. You were right about the msys2_shell.bat which I kept using. I proceeded with the steps you advised and installed about a 1 GB of additional packages. `gcc -dumpmachine` and `g++ -umpmachine` now show `x86_64-w64-mingw32` as you said, however, the errors are still the same. Still a bunch of `C:/msys64/mingw64/include/c++/4.9.2/bits/stringfwd.h:52:3: error: template with C linkage` and related errors. I keep getting these even with MS Visual Studio 2013 but I wonder why if the code compiles under Linux... – Kyselejsyreček Apr 27 '15 at 13:02
  • You need to create a small, self contained sample (a single C++ function for example) that compiles on GNU/Linux but not on MSYS2/MinGW-w64. Without being able to reproduce your problem I cannot investigate it. – Ray Donnelly Apr 28 '15 at 17:01
0

The problem turned out not to be related to OpenGL, neither to MSYS(2)/MinGW(-w64) or MS Visual Studio 2013.

For anyone who might be facing the same problems as I was, the vast majority of all the error reports was generated because there was a custom windows.h header file present in my project's include path. A header with the same name is present in standard Windows header library and is essential for proper functionality of other libraries.

Lesson learned: never try to name a file with system-specific code after the operating system.

Kyselejsyreček
  • 459
  • 1
  • 3
  • 16