<p>Is it possible to compile and run OpenGL programs from under Cygwin? If yes, how?</p>

[{'answer_id': 14346, 'author': 'Ashwin Nanjappa', 'author_id': 1630, 'author_profile': 'https://Stackoverflow.com/users/1630', 'pm_score': 5, 'selected': True, 'text': '<p>It is possible to compile and run OpenGL programs under Cygwin. I illustrate the basic steps here:</p>\n\n<ol>\n<li><p>I assume you know OpenGL programming. If not, get the <a href="http://www.opengl-redbook.com/" rel="noreferrer">Red Book</a> (<em>The OpenGL Programming Guide</em>). It is mandatory reading for OpenGL anyway.</p></li>\n<li><p>I assume you have Cygwin installed. If not, visit <a href="http://www.cygwin.com/" rel="noreferrer">cygwin.com</a> and install it.</p></li>\n<li><p>To compile and run OpenGL programs, you need the Cygwin package named <strong>opengl</strong>. In the Cygwin installer, it can be found under the <em>Graphics section</em>. Please install this package.</p></li>\n<li><p>Write a simple OpenGL program, say <em>ogl.c</em>.</p></li>\n<li><p>Compile the program using the flags <strong>-lglut32 -lglu32 -lopengl32</strong>. (This links your program with the GLUT, GLU and OpenGL libraries. An OpenGL program might typically use functions from all the 3 of them.) For example:</p>\n\n<blockquote>\n  <p>$ gcc ogl.c -lglut32 -lglu32 -lopengl32</p>\n</blockquote></li>\n<li><p>Run the program. It\'s as simple as that!</p></li>\n</ol>\n'}, {'answer_id': 24605, 'author': 'Jared Updike', 'author_id': 2543, 'author_profile': 'https://Stackoverflow.com/users/2543', 'pm_score': 1, 'selected': False, 'text': "<p>I remember doing this once with some success, a few years ago, basically trying to cross compile a small Linux OpenGL C++ program. I do recall problems with Windows OpenGL drivers being behind the times (due to MS's focus on DirectX). I had NVidia OpenGL and DirectX drivers installed on my Windows system, but cygwin/g++ seemed to want to only use the Microsoft OpenGL DLLs, many years old, which do not have the latest support for all the ARB extensions, like shader programs, etc. YMMV.</p>\n"}, {'answer_id': 1676468, 'author': 'tumnus', 'author_id': 202933, 'author_profile': 'https://Stackoverflow.com/users/202933', 'pm_score': 2, 'selected': False, 'text': "<p>If the above doesn't work (and it didn't for me), try the following (which did!)</p>\n\n<p>gcc ogl.c -lglut -lglu -lgl</p>\n"}, {'answer_id': 68074857, 'author': 'Adriana', 'author_id': 6908795, 'author_profile': 'https://Stackoverflow.com/users/6908795', 'pm_score': 1, 'selected': False, 'text': '<p>I do not normally post answers this long, but this one is worth it.</p>\n<p>I will present a <strong>Windows 10 64-bit</strong> setup for <strong>Cygwin</strong> that uses <em>the same libraries</em> as <strong>Visual Studio</strong>. You will be able to use both development environments with the same code (same includes and libraries), so you can switch between the two as you see fit.</p>\n<p>You need three libraries: <strong>OpenGL</strong>, <strong>GLEW</strong>, and <strong>GLFW</strong>.</p>\n<ol>\n<li><em>OpenGL</em></li>\n</ol>\n<p><strong>Visual Studio:</strong> The following default locations are valid for current versions of Windows 10 and Visual Studio 2019.</p>\n<p>OpenGL static library:</p>\n<pre><code>C:\\Program Files(x86)\\Microsoft Visual Studio\\2019\\Community\\SDK\\ScopeCPPSDK\\vc15\\lib\\SDK\\lib\\opengl32.lib\n</code></pre>\n<p>OpenGL DLL:</p>\n<pre><code>C:\\Windows\\SysWOW64\\opengl32.dll\n</code></pre>\n<p>The <code>opengl32.lib</code> library will need to be specified under the VS project <code>Properties -&gt; Configuration Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies</code>. The same applies for all other dynamic libraries under Visual Studio. I will not mention it again.</p>\n<p><strong>Cygwin:</strong></p>\n<p>OpenGL static library default location:</p>\n<pre><code>/lib/w32api/libopengl32.a\n</code></pre>\n<p>OpenGL dynamic library (uses the Windows DLL):</p>\n<pre><code>C:\\Windows\\SysWOW64\\opengl32.dll\n</code></pre>\n<ol start="2">\n<li><em>GLEW</em></li>\n</ol>\n<p><strong>Visual Studio:</strong> Download 32-bit/64-bit binaries from <code>http://glew.sourceforge.net/</code> and install in a custom folder, say <code>C:\\OpenGL\\glew-2.1.0</code>. The same download works for both Visual Studio and Cygwin.</p>\n<p>GLEW headers (to <code>#include GL/glew.h</code>):</p>\n<pre><code>C:\\OpenGL\\glew-2.1.0\\include\n</code></pre>\n<p>GLEW static library:</p>\n<pre><code>C:\\OpenGL\\glew-2.1.0\\lib\\Release\\x64\\glew32.lib\n</code></pre>\n<p>GLEW DLL:</p>\n<pre><code>C:\\OpenGL\\glew-2.1.0\\bin\\Release\\x64\\glew32.dll\n</code></pre>\n<p>These can be specified in your VS project\'s Properties menu.</p>\n<p><strong>Cygwin:</strong> You can link against this library from Cygwin as-is, meaning you can specify its download directory for the <code>INCS</code>, <code>LIBS</code>, and <code>LDLIBS</code> variables in your <code>Makefile</code> as follows (consistent with the download directory specified above):</p>\n<p>GLEW headers directory:</p>\n<pre><code>/cygdrive/c/OpenGL/glew-2.1.0/include\n</code></pre>\n<p>GLEW static library directory:</p>\n<pre><code>/cygdrive/c/OpenGL/glew-2.1.0/lib/Release/x64\n</code></pre>\n<p>GLEW dynamic library directory:</p>\n<pre><code>/cygdrive/c/OpenGL/glew-2.1.0/bin/Release/x64\n</code></pre>\n<p>With these values for <code>INCS</code>, <code>LIBS</code>, and <code>LDLIBS</code> respectively, you can then link using the UNIX naming conventions as shown in the complete <code>Makefile</code>, at the bottom of the post.</p>\n<ol start="3">\n<li><em>GLFW</em></li>\n</ol>\n<p>This can be downloaded at <code>https://www.glfw.org/download</code>. For our 64-bit setup, you need the Windows 64-bit precompiled binaries. You can place it also in a custom folder, say <code>C:\\OpenGL\\glfw-3.3.4.bin.WIN64</code>. The same download works for both VS and Cygwin.</p>\n<p><strong>Visual Studio:</strong>\nYou can specify directly the download locations into your project Properties for headers (to <code>#include GLFW/glfw3.h</code> in your source code) and DLLs (to have VS link against these libraries), respectively.</p>\n<p><strong>Cygwin:</strong>\nFor Cygwin, GLFW is trickier, because you can no longer link against it directly from the download location. You need to:</p>\n<p>(a) copy the headers, static, and dynamic libraries from the download locations:</p>\n<pre><code>C:\\OpenGL\\glfw-3.3.4.bin.WIN64\\include\\GLFW\\*.h\nC:\\OpenGL\\glfw-3.3.4.bin.WIN64\\lib-mingw-w64\\*.a\nC:\\OpenGL\\glfw-3.3.4.bin.WIN64\\lib-mingw-w64\\*.dll\n</code></pre>\n<p>...into your toolchain\'s (MinGW\'s) respective locations:</p>\n<p>GLFW headers (create the <code>include</code> directory):</p>\n<pre><code>/usr/x86_64-w64-mingw32/include/GLFW/*.h\n</code></pre>\n<p>GLFW static libraries:</p>\n<pre><code>/usr/x86_64-w64-mingw32/lib/*.a\n</code></pre>\n<p>GLFW dynamic libraries:</p>\n<pre><code>/usr/x86_64-w64-mingw32/bin/*.dll\n</code></pre>\n<p>(b) place the dynamic library location into your PATH environment variable, editable in your <code>.bash_profile</code> file in your home directory.</p>\n<p>The <code>Makefile</code> for Cygwin is:</p>\n<pre><code>CC=/usr/bin/x86_64-w64-mingw32-c++.exe\nOPTS=-std=c++11\nDEBUG=-g\nCFLAGS=-Wall -c ${DEBUG}\n\nINCS=  -I.\\\n       -I/cygdrive/c/OpenGL/glew-2.1.0/include\\\n       -I/cygdrive/c/cygwin64/usr/x86_64-w64-mingw32\n\nLIBS=   -L/usr/lib\\\n        -L/cygdrive/c/OpenGL/glew-2.1.0/lib/Release/x64\\\n        -L/cygdrive/c/cygwin64/usr/x86_64-w64-mingw32/lib\n\nLDLIBS= -L/bin\\\n        -L/cygdrive/c/OpenGL/glew-2.1.0/bin/Release/x64\\\n        -L/cygdrive/c/cygwin64/usr/x86_64-w64-mingw32\\bin\n\nProgram.o:  Program.cpp\n            ${CC} ${OPTS} ${INCS} -c $&lt;\n\nProgram:    Program.o\n            ${CC} ${OPTS} ${LIBS} ${LDLIBS} Program.o -lopengl32 -lglew32 -lglew32.dll -lglfw3 -lgdi32 -luser32 -o Program\n</code></pre>\n<p>With this setup, you can use the same exact source code files in both VS and Cygwin. You can compile, link, and run <code>Program.exe</code> from its directory in Cygwin with:</p>\n<pre><code>$ make Program\n$ ./Program.exe\n</code></pre>\n<p>You can run from VS a Cygwin-compiled program by opening the existing <code>*.exe</code> as an SLN project and running it using the IDE interface. Conversely, you can run the VS executable (created by VS in <code>Project/Debug</code> or <code>Project/Release</code>) directly from the Cygwin command line with the command above.</p>\n<p>The includes are:</p>\n<pre><code>#include &lt;GL/glew.h&gt;\n#include &lt;GLFW/glfw3.h&gt;\n</code></pre>\n<p>No changes whatsoever will have to be made in the source code to switch back and forth b/w VS and Cygwin. Happy coding :-)</p>\n'}]
['https://Stackoverflow.com/questions/14344', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1630/']