Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up GLFW with MinGW

Tags:

mingw

glfw

I'm trying to learn OpenGL with GLFW, but I'm having some problems.

This is my main.cpp:

#include <GL/glfw.h>

int main()
{
    glfwInit();
    glfwSleep( 1.0 );
    glfwTerminate();
}

This is my project's folder structure:

Project
+- glfw.dll
+- main.cpp

This is where I extracted the GLFW files:

MinGW
+- include
|   +- GL
|      +- glfw.h
+- lib
   +- libglfw.a
   +- libglfwdll.a

And this is how I try to build the program:

g++ main.cpp -o main.exe -lglfwdll

And these are the errors I'm getting:

C:\Users\Dark\AppData\Local\Temp\cc0ZgTVp.o:main.cpp:(.text+0xf): undefined reference to `_glfwInit'
C:\Users\Dark\AppData\Local\Temp\cc0ZgTVp.o:main.cpp:(.text+0x25): undefined reference to `_glfwSleep'
C:\Users\Dark\AppData\Local\Temp\cc0ZgTVp.o:main.cpp:(.text+0x2a): undefined reference to `_glfwTerminate'
collect2.exe: error: ld returned 1 exit status

Am I missing something?

like image 277
Darkwater Avatar asked Oct 14 '12 21:10

Darkwater


People also ask

Can I use GLFW with C++?

3.1 - What compilers are supported by GLFW? Currently, GLFW releases are tested with MinGW, MinGW-w64 and Visual C++ 2010, 2012, 2013 and 2015, but it should work with any compiler that supports C99 (C89 on Windows). Very old development environments may require updated system headers.

How do I compile a GLFW program?

To compile GLFW for Wayland, you need to have the Wayland and xkbcommon development packages installed. They are not needed to build or run programs that use GLFW. On Debian and derivates like Ubuntu and Linux Mint you will need the libwayland-dev , libxkbcommon-dev , wayland-protocols and extra-cmake-modules packages.

Does GLFW work with C?

GLFW is an Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan development on the desktop. It provides a simple API for creating windows, contexts and surfaces, receiving input and events. GLFW is written in C and supports Windows, macOS, X11 and Wayland.

How do I add GLFW to my project?

Add the root directory of the GLFW source tree to your project. This will add the glfw target to your project. Once GLFW has been added, link your application against the glfw target.


1 Answers

Download the binaries here according to your environment.

Project
+- glfw3.dll (You can put it in System32 or SysWOW64 instead.)
+- main.cpp

MinGW
+- include
|   +- GLFW
|      +- glfw3.h
+- lib
   +- libglfw3.a
   +- libglfw3dll.a (Renamed from glfw3dll.a)

g++ -c main.cpp
g++ -o main.exe main.o -lglfw3dll -lopengl32
like image 55
chehsunliu Avatar answered Jan 05 '23 03:01

chehsunliu