GLFW链接问题Visual Studio 2012 [英] GLFW linking issue Visual Studio 2012
问题描述
这促使我疯狂,我想静态链接到GLFW.lib,按照4.2.1节。的readme.html文件,我已经添加了glfw.lib和opengl32.lib到VS上的链接器的附加依赖性部分。
我也添加了dir包括glfw.lib到linker> general下的附加库目录部分。
当然我已经在我的项目中包含了glfw.h文件,但我还在...
错误1错误LNK2019:未解析的外部符号_glfwInit在函数_main中引用C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\ Spark\main.obj Spark
错误2错误LNK2019:未解析的外部符号_glfwTerminate在函数_main中引用C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\\ \\ main.obj Spark
错误3错误LNK2019:未解析的外部符号_glfwOpenWindow在函数_main中引用C:\Users\Smith_000\Documents\Visual Studio 2012 \Projects\Spark\Spark\main .obj Spark
错误4错误LNK2019:未解析的外部符号_glfwSwapBuffers在函数_main中引用C:\Users\Smith_000\Documents\Visual Studio 2012 \Projects\Spark\Spark\main.obj Spark
错误5错误LNK2019:未解析的外部符号_glfwGetWindowParam在函数_main中引用C:\Users\Smith_000\Documents\Visual Studio 2012 \Projects\Spark\Spark\main.obj Spark
错误6错误LNK2019:未解析的外部符号_glfwGetKey在函数_main中引用C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Spark\main.obj Spark
错误7错误LNK1120:6未解决的外部C:\Users\Smith_000\Documents\Visual Studio 2012\Projects\Spark\Debug\Spark.exe 1 1 Spark
使用以下(示例)代码...
#include< glfw.h>
#include< stdlib.h>
int main(void)
{
int running = GL_TRUE;
//初始化GLFW
if(!glfwInit())
{
exit(EXIT_FAILURE);
}
//打开一个OpenGL窗口
if(!glfwOpenWindow(300,300,0,0,0,0,0,0,GLFW_WINDOW))
{
glfwTerminate();
exit(EXIT_FAILURE);
}
//主循环
while(正在运行)
{
// OpenGL渲染到这里...
glClear(GL_COLOR_BUFFER_BIT );
//交换前后渲染缓冲区
glfwSwapBuffers();
//检查ESC键是否被按下或窗口被关闭
running =!glfwGetKey(GLFW_KEY_ESC)&&
glfwGetWindowParam(GLFW_OPENED);
}
//关闭窗口并终止GLFW
glfwTerminate();
//退出程序
exit(EXIT_SUCCESS);
}
我做错了什么?
解决方案确保您的glfw.dll在文件夹中与您的.exe文件。如果这没有帮助,添加另一个库glu32.lib。
我通过在main函数之前添加这个库来添加库。有了这个,你看到你有linek没有通过选项和菜单。
#pragma comment(lib,GLFW.lib )
#pragma comment(lib,opengl32.lib)
#pragma comment(lib,glu32.lib)
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?
解决方案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")
这篇关于GLFW链接问题Visual Studio 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!