OpenGL链接问题

时间:2016-01-01 13:23:06

标签: c++ opengl linker visual-studio-2015

我正在尝试用c ++构建一个OpenGL应用程序。我使用glew和glfw库。现在我想创建一些纹理,但现在它说:

1>model.obj : error LNK2019: unresolved external symbol __imp_glBindTexture referenced in function "public: void __cdecl Texture::Bind(unsigned int)" (?Bind@Texture@@QEAAXI@Z)
1>model.obj : error LNK2019: unresolved external symbol __imp_glGenTextures referenced in function "public: bool __cdecl Texture::Load(void)" (?Load@Texture@@QEAA_NXZ)
1>model.obj : error LNK2019: unresolved external symbol __imp_glTexImage2D referenced in function "public: bool __cdecl Texture::Load(void)" (?Load@Texture@@QEAA_NXZ)
1>model.obj : error LNK2019: unresolved external symbol __imp_glTexParameterf referenced in function "public: bool __cdecl Texture::Load(void)" (?Load@Texture@@QEAA_NXZ)
1>C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\lib\magickdb.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
1>C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\lib\magickrl.lib : warning LNK4272: library machine type 'X86' conflicts with target machine type 'x64'
1>C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\x64\Debug\OpenGLTest3.exe : fatal error LNK1120: 16 unresolved externals

到目前为止一切工作(glGenVertexArrays(),glDrawArrays()等),只有纹理函数(glGenTextures(),glBindTexture()等)不起作用。 链接器设置如下:glew32.lib;glfw3.lib;assimp.lib;devil.lib;magickdb.lib;magickrl.lib;%(AdditionalDependencies)

VC包括dir: C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\include;$(IncludePath) VC lib目录: C:\Users\Dynamitos5\Documents\cuda\OpenGLTest\external\lib;$(LibraryPath)

2 个答案:

答案 0 :(得分:4)

直到OpenGL 1.1的所有功能都直接在opengl32.lib库中实现。所有其他功能都可通过扩展获得,并且必须手动加载(或使用像glew这样的库)。

在您的情况下,您错过了再次链接opengl32.lib

答案 1 :(得分:0)

这里发生了一些事情...... OpenGL附带Windows,但仅限于带有opengl32.lib的OpenGL 1.1。因此,对于所有后续OpenGL版本,需要扩展库,例如glew。现在,freeglut包含opengl32.lib但glew没有,所以如果你使用glew,你必须自己包含opengl32.lib。在Visual Studio下,右键单击项目(以粗体显示),然后在Properties / Linker / Input中添加openg32.lib。无需在C / C ++ / General或链接器/常规属性中添加任何其他目录 - opengl32.lib随Windows一起提供,Visual Studio知道在哪里找到它但仍需要被告知链接它!最后,在可执行文件所在的Visual Studio Debug目录中复制相应的动态库,例如freeglut.dll或glew32.dll。

相关问题