如何修复OpenGL编译错误,“未解析的外部符号”

时间:2011-02-15 00:20:04

标签: visual-c++ linker-errors

我正在尝试编写一个OpenGL程序来操作相机。但是代码没有编译。

All of my source code can be found here

错误是:

1>------ Rebuild All started: Project: Lab4, Configuration: Debug Win32 ------
1>Build started 2/14/2011 7:17:54 PM.
1>_PrepareForClean:
1>  Deleting file "Debug\Lab4.lastbuildstate".
1>InitializeBuildStatus:
1>  Touching "Debug\Lab4.unsuccessfulbuild".
1>ClCompile:
1>  camera.cpp
1>camera.obj : error LNK2019: unresolved external symbol "public: void __thiscalllVector3::normalize(void)" (?normalize@Vector3@@QAEXXZ) referenced in function "public: void __thiscall Camera::set(class Point3,class Point3,class Vector3)" (?set@Camera@@QAEXVPoint3@@0VVector3@@@Z)
1>camera.obj : error LNK2019: unresolved external symbol "public: class Vector3 __thiscall Vector3::cross(class Vector3)" (?cross@Vector3@@QAE?AV1@V1@@Z) referenced in function "public: void __thiscall Camera::set(class Point3,class Point3,class Vector3)" (?set@Camera@@QAEXVPoint3@@0VVector3@@@Z)
1>camera.obj : error LNK2019: unresolved external symbol "public: float __thiscall Vector3::dot(class Vector3)" (?dot@Vector3@@QAEMV1@@Z) referenced in function "private: void __thiscall Camera::setModelviewMatrix(void)" (?setModelviewMatrix@Camera@@AAEXXZ)
1>C:\Users\Andrew Davis\Documents\Visual Studio 2010\Projects\Lab4\Debug\Lab4.exe : fatal error LNK1120: 3 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.08
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

我已经在我的链接器中有了这个:

opengl32.lib glu32.lib glut32.lib freeglut.lib

有什么建议吗?提前谢谢!

2 个答案:

答案 0 :(得分:1)

您必须为以下功能提供一个主体,即使它是空的。 Vector3::normalize(), Vector3::cross(), Vector3::dot()。例如

void normalize(){ //do something}

您正在调用它们,因此您没有实现链接器错误。

答案 1 :(得分:0)

这不是OpenGL或它的库的问题。看起来如果camera.cpp使用了一些不同的类,但它的实现要么不构建,要么没有链接。

编辑:只是看看你的代码

如何实施Vector3::normalize()Vector3::cross()Vector3::dot()? Pastebin中的第86,107和108行。