-1

I installed GLFW 3 (include to include folder to VS\C\include, lib to VS\C\lib and dll to SySWOW54). Now when I try to compile a first example from documentation

#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
static void error_callback(int error, const char* description)
{
    fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
    GLFWwindow* window;
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
        exit(EXIT_FAILURE);
    window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, key_callback);
    while (!glfwWindowShouldClose(window))
    {
        float ratio;
        int width, height;
        glfwGetFramebufferSize(window, &width, &height);
        ratio = width / (float) height;
        glViewport(0, 0, width, height);
        glClear(GL_COLOR_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
        glBegin(GL_TRIANGLES);
        glColor3f(1.f, 0.f, 0.f);
        glVertex3f(-0.6f, -0.4f, 0.f);
        glColor3f(0.f, 1.f, 0.f);
        glVertex3f(0.6f, -0.4f, 0.f);
        glColor3f(0.f, 0.f, 1.f);
        glVertex3f(0.f, 0.6f, 0.f);
        glEnd();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}

this compilation errors are displayed

1>------ Build started: Project: GLFW3_test, Configuration: Debug Win32 ------
1>Source.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glOrtho@48 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwSetErrorCallback referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwCreateWindow referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwDestroyWindow referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwWindowShouldClose referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwSetWindowShouldClose referenced in function "void __cdecl key_callback(struct GLFWwindow *,int,int,int,int)" (?key_callback@@YAXPAUGLFWwindow@@HHHH@Z)
1>Source.obj : error LNK2019: unresolved external symbol _glfwGetFramebufferSize referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwPollEvents referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwSetKeyCallback referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwGetTime referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwMakeContextCurrent referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function _main
1>E:\!MyProjects\GLFW3_test\Debug\GLFW3_test.exe : fatal error LNK1120: 23 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

How can I fix that?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Toisen
  • 41
  • 2
  • 6
  • `include to include folder to VS\C\include, lib to VS\C\lib and dll to SySWOW54` You don't really need to do this. Just point Visual studio to your library's path in `Project properties -> VC Directories`. Then add your `lilbaryFilename.lib` file to linker input: `Project properties -> Linker -> Input -> Additional dependencies` – Ivan Aksamentov - Drop Nov 22 '13 at 14:07
  • Need to say that your "example from documentation" uses obsolete GL features. Make sure that you will find something more up-to-date to learn =) – Ivan Aksamentov - Drop Nov 22 '13 at 14:10

2 Answers2

5

I had this same problem in Visual C++ 2010. By adding #define GLFW_DLL before the#include, this allows the compiler/linker in VS to build the program successfully, as well as linking to glfw3.lib, opengl32.lib, and glu32.lib.

MrTux
  • 32,350
  • 30
  • 109
  • 146
1

Make sure to link against glfw3.lib and opengl32.lib.

You may have to adjust /LIBPATH: to point to where you installed GLFW.

genpfault
  • 51,148
  • 11
  • 85
  • 139