GLFW linking issue Visual Studio 2012

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

This is driving me mad, I want to statically link to GLFW.lib, following section 4.2.1. of the readme.html file provided I have added glfw.lib and opengl32.lib to the additional dependancies section of the linker on VS.

I've also added the dir including glfw.lib to the additional library directories section under linker > general.

And of course I have included the glfw.h file in my project, yet I'm still getting...

Error   1   error LNK2019: unresolved external symbol _glfwInit referenced in function _main    C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark Error   2   error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main   C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark Error   3   error LNK2019: unresolved external symbol _glfwOpenWindow referenced in function _main  C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark Error   4   error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function _main C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark Error   5   error LNK2019: unresolved external symbol _glfwGetWindowParam referenced in function _main  C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark Error   6   error LNK2019: unresolved external symbol _glfwGetKey referenced in function _main  C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj   Spark Error   7   error LNK1120: 6 unresolved externals   C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Debug\Spark.exe  1   1   Spark 

With the following (example) code...

#include <glfw.h> #include <stdlib.h>  int main( void ) {     int running = GL_TRUE;      // Initialize GLFW     if( !glfwInit() )     {         exit( EXIT_FAILURE );     }      // Open an OpenGL window     if( !glfwOpenWindow( 300,300, 0,0,0,0,0,0, GLFW_WINDOW ) )     {         glfwTerminate();         exit( EXIT_FAILURE );     }      // Main loop     while( running )     {         // OpenGL rendering goes here...         glClear( GL_COLOR_BUFFER_BIT );         // Swap front and back rendering buffers         glfwSwapBuffers();         // Check if ESC key was pressed or window was closed         running = !glfwGetKey( GLFW_KEY_ESC ) &&         glfwGetWindowParam( GLFW_OPENED );     }      // Close window and terminate GLFW     glfwTerminate();      // Exit program     exit( EXIT_SUCCESS ); } 

What am I doing wrong?

回答1:

Make sure you have glfw.dll in folder with your .exe file. If this wont help, add another library glu32.lib.

I use to add libraries in code by adding this before main function. With this you see wich libraries you have linek without diging through options and menus.

#pragma comment(lib, "GLFW.lib") #pragma comment(lib, "opengl32.lib") #pragma comment(lib, "glu32.lib") 


回答2:

Perhaps the reason is because you are linking to these libraries in only one build mode, say, release.

Second possible reason: (Correct me if I am wrong, as I am not 100% sure of this). The LIB files might have been built in different compiler. For example, the LIB was compiled in MinGW, and you are linking to it with the MSVC++ compiler.

Third possible reason: Consider what version of GLFW you are using (As in 32 bit, 64 bit).



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!