Tuesday, July 18, 2017

Setting up Eclipse and OpenGL using MSYS2/MinGW - Part 1

I am trying to learn some computer graphics and have decided to use Eclipse in Windows. If you notice some mistakes in this tutorial, please do not hesitate to drop a comment.

I. Installing the Eclipse IDE.
I will be using the Eclipse IDE for C/C++ Developers. If you have an existing Eclipse IDE and used it for anything other than C/C++, then you need to download and install the CDT plugin for Eclipse. In this tutorial, I will be assuming that you'd want to use a fresh install of Eclipse for C/C++.
  1. Head on over to https://www.eclipse.org/downloads/eclipse-packages/ and download the package. Choose the appropriate version of the package for your operating system, whether 32-bit or 64-bit.
  2. After downloading the ZIP file, extract it to a convenient location, then create a shortcut for the Eclipse executable and place it somewhere convenient like your desktop or Windows Taskbar for easier access later. Let us now move on to the next part.

II. Installing MSYS2/MinGW.
  1. Download the appropriate msys2 one click installer for your OS architecture here: http://www.msys2.org/ and follow the installation instructions on that page. Take note of the location where you installed msys2 because we will need it in the following steps.
  2. After you've finished the installation (including the updating), we will now update our PATH variable to include the path where our compilers and libraries will be installed.
  3. Open Control Panel » System » Advanced » Environment Variables
  4. We will now add an new item to the PATH variable. You probably need Administrator privileges for this. Assuming you followed all the instructions in the msys2.org website and installed msys2 to to the default location, add a new item pointing to C:\msys32\mingw32\bin if you are on a 32-bit system. If you are on a 64-bit system, add two new entries pointing C:\msys64\mingw32\bin and C:\msys64\mingw32\bin. 
  5. Apply and save changes to the PATH variable and start your msys2 shell.

III. Installing the compilers and OpenGL libraries.
  1. If you are using a 64-bit system, enter this command in the prompt then wait for the installation to finish:
  2. pacman -S gcc
    After the previous installation is done, enter the next command and wait for it to finish:
    pacman -S mingw-w64-x86_64-gcc
    After the installation, you should now have a working suite of compilers for C and C++!
  3. To check if the install is indeed successful, type gcc or g++ in the prompt and you should be greeted with an error about no input files. That should indicate a successful install since you didn't really include a source file to compile in the command.
  4. As for the OpenGL specific libraries, msys2 makes it convenient. If you are using a 32-bit system, type in the following commands, accept all prompts by typing "Y", and then wait for the installation to finish:
  5. pacman -S mingw-w64-i686-glfw mingw-w64-i686-glew mingw-w64-i686-freeglut mingw-w64-i686-freeimage mingw-w64-i686-glm
    For a 64-bit system, enter the following command:
    pacman -S mingw-w64-i686-glfw mingw-w64-x86_64-glfw mingw-w64-i686-glew mingw-w64-x86_64-freeimage mingw-w64-x86_64-glew mingw-w64-i686-freeglut mingw-w64-x86_64-freeglut mingw-w64-i686-glm mingw-w64-x86_64-glm
    Once the installation is done, we can now proceed to creating our Eclipse project template. In Part 2 of this tutorial, we will set up Eclipse to use OpenGL in our project.

2 comments:

  1. Hello, i am reading your post in january, 2020. Thanks for creating this information. Actually i am working on windows and eclipse shows that no such file for the header

    #include

    i have downloaded GLFW and now i don't know what to do.
    can you please help me...

    ReplyDelete
  2. I've been trying for an entire day to figure out why everything in my project was building, but i wasnt getting any autocomplete / suggestions regarding opengl.
    After following this guide everythings, apart from more organized, sadly still acting the same way.
    I have to add I'm using a C project & for some reason functions like 'glShaderSource' are not autocompleting and only showing up as 'existing' (without parameter information etc), but functions like 'glClearColor' work fine . . .

    ReplyDelete