Sign in to follow this  
Followers 0
Prognatus

OpenGL
Need help Setting up GLFW for VS2010

7 posts in this topic

I get this error every time i debug this code. I downloaded the new version of glfw from www.glfw.org. I have linked both the library's  glfw3.lib and glfw3dll.lib to the linker  input and general.
 
#define GLFW_DLL
#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 */

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

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

    glfwTerminate();
    return 0;
}




1>main.obj : error LNK2019: unresolved external symbol __imp__glfwPollEvents referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glfwSwapBuffers referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glfwWindowShouldClose referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glfwMakeContextCurrent referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glfwTerminate referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glfwCreateWindow referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol __imp__glfwInit referenced in function _main
1>c:\users\william\documents\visual studio 2010\Projects\test 1\Debug\test 1.exe : fatal error LNK1120: 7 unresolved externals
0

Share this post


Link to post
Share on other sites

I have linked both the library's  glfw3.lib and glfw3dll.lib to the linker  input and general.


I'm not sure that is a good idea. I'm not familiar with the precompiled build for GLFW but from a quick glance I got the impression glfw3.lib is for statically linking GLFW while glfw3dll.lib is for dynamically linking it. Supplying both to the linker might have you end up with errors like that.
That said, I would in general advise to only link something as small and simple like GLFW dynamically if there is a specific need for that. So my advice would be to remove the define for GLFW_DLL and only link glfw3.lib.
0

Share this post


Link to post
Share on other sites

I have linked both the library's  glfw3.lib and glfw3dll.lib to the linker  input and general.


I'm not sure that is a good idea. I'm not familiar with the precompiled build for GLFW but from a quick glance I got the impression glfw3.lib is for statically linking GLFW while glfw3dll.lib is for dynamically linking it. Supplying both to the linker might have you end up with errors like that.
That said, I would in general advise to only link something as small and simple like GLFW dynamically if there is a specific need for that. So my advice would be to remove the define for GLFW_DLL and only link glfw3.lib.


I tried what you said but i still get the same error
0

Share this post


Link to post
Share on other sites
Is it possible you are linking an x86 library into an x64 project or vice versa? Edited by BitMaster
0

Share this post


Link to post
Share on other sites
[edit]

OK, I just tried to replicate your problem and was able to do so. Make absolutely sure that you have glfw3.lib OR glfw3dll.lib added to "project properties->Linker->Input->Additional Dependencies" for EVERY configuration. I think that you added the library for either your Release or Debug configuration, but not both. I've done this more than once. I found it helpful to get into the habit of changing the project configuration to "All Configurations" before setting directories and adding libraries. Saves a LOT of headaches! Edited by MarkS
0

Share this post


Link to post
Share on other sites
I manged to fix it. What i did wrong was download the win64 version of glfw instead of the win32. But now i have a new problem every time i call Initglew() my program clashes.

//Sets the error callback in case of error
glfwSetErrorCallback(Error_callback);

//initailize glfw
if (!glfwInit())
{
exit(EXIT_FAILURE);
return false;
}
//create window
window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);

if (!window)
{
glfwTerminate();
exit(EXIT_FAILURE);
return false;
}


glewExperimental=true;
GLenum err=glewInit();
if(err!=GLEW_OK)
{
//Problem: glewInit failed, something is seriously wrong.
glfwTerminate();
exit(EXIT_FAILURE);
return false;
}
//set window context
glfwMakeContextCurrent(window);
//sets Key callback
glfwSetKeyCallback(window, Key_callback);

return true;
1

Share this post


Link to post
Share on other sites

glfwMakeContextCurrent(window) needs to be called before you initialize GLEW.



Thx that solved my problem.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0