-2

Well, im trying to get started with GLFW, but i am getting some troubles when i try to link the libraries.

I'm trying to compile the first example of the GLFW page.

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

Compiler

g++ -L. libglfw3dll.a -lglfw3 -lopengl32 main.cpp

In my project folder i have

glfw3.dll

libglfw3dll.a

When i try to compile it, i get this linker error

undefined reference to `__imp_glClear'

What am i doing wrong?

/---------------------- Edit ----------------------------/

Sorry, i forgot to say some things, that could clarify a little bit my situation...

I'm working on Windows 10, 64 bits.

Compiler -> Mingw Binaries -> Downloaded from the official page

I tried to compile the code with the static libraries and i got a lot of undefined references.

g++ -L. -lopengl32 -lglu32 -lgdi32 -lglfw3  main.cpp

Then, i tried to use the dynamic library, glfw.dll. I also linked the glfwdll.a library and defined the GLFW_DLL macro before including the headers.

g++ -L. libglfw3dll.a -lglfw3 -lopengl32 main.cpp

with the last option, i got just 1 undefined reference

undefined reference to `__imp_glClear'

I understand that this is from the opengl32 library.

I also understand that I'm missing something that I can't find.

Here I come again, can you give me a hand, and tell me what I'm missing?

Thanks!

  • Go to section _GLAD_ on [learnopengl](https://learnopengl.com/#!Getting-started/Creating-a-window). That might be the issue here. – Mário Feroldi Dec 23 '17 at 01:52

1 Answers1

0

Please read the manual GLFW: Building applications

Bellow is cited the part for GNU environment. If you develop your application for windows, you can find suitable instructions there too.

GLFW supports pkg-config, and the glfw3.pc pkg-config file is generated when the GLFW library is built and is installed along with it. A pkg-config file describes all necessary compile-time and link-time flags and dependencies needed to use a library. When they are updated or if they differ between systems, you will get the correct ones automatically.

A typical compile and link command-line when using the static version of the GLFW library may look like this:

cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --static --libs glfw3`

If you are using the shared version of the GLFW library, simply omit the --static flag.

cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --libs glfw3`

You can also use the glfw3.pc file without installing it first, by using the PKG_CONFIG_PATH environment variable.

env PKG_CONFIG_PATH=path/to/glfw/src cc `pkg-config --cflags glfw3` -o myprog myprog.c `pkg-config --libs glfw3`

The dependencies do not include OpenGL or GLU, as GLFW loads any OpenGL, OpenGL ES or Vulkan libraries it needs at runtime and does not use GLU. On OS X, GLU is built into the OpenGL framework, so if you need GLU you don't need to do anything extra. If you need GLU and are using Linux or BSD, you should add the glu pkg-config package.

cc `pkg-config --cflags glfw3 glu` -o myprog myprog.c `pkg-config --libs glfw3 glu`

Note

GLU has been deprecated and should not be used in new code, but some legacy code requires it.

If you are using the static version of the GLFW library, make sure you don't link statically against GLU.

cc `pkg-config --cflags glfw3 glu` -o myprog myprog.c `pkg-config --static --libs glfw3` `pkg-config --libs glu`
273K
  • 29,503
  • 10
  • 41
  • 64