在编译需要GLUT的C ++程序时,如何解决链接器问题?

时间:2010-02-07 18:43:30

标签: c++ opengl linker compiler-errors glut

我正在尝试编译这个利用GLUT32库的C ++程序。

现在我收到以下错误:

  

错误1错误LNK2001:未解决   外部符号   _gluPerspective @ 32 Camera.obj soundCube   错误2错误LNK2001:未解决   外部符号   _gluLookAt @ 72 Camera.obj soundCube错误3错误LNK2001:未解决   外部符号   __imp__glMaterialfv @ 12 GLWindow.obj soundCube   错误4错误LNK2001:未解决   外部符号   __imp__glClear @ 4 GLWindow.obj soundCube错误5错误LNK2001:未解决   外部符号   __imp__glClearColor @ 16 GLWindow.obj soundCube   错误6错误LNK2001:未解决   外部符号   __imp__glMaterialf @ 12 GLWindow.obj soundCube错误7错误LNK2001:未解决   外部符号   __imp__glEnd @ 0 GLWindow.obj soundCube错误8错误LNK2001:未解决   外部符号   __imp__glRasterPos2f @ 8 GLWindow.obj soundCube   错误9错误LNK2001:未解决   外部符号   __imp__timeGetTime @ 0 GLWindow.obj soundCube错误10错误LNK2001:未解决   外部符号   __imp__glDisable @ 4 GLWindow.obj soundCube   错误11错误LNK2001:未解决   外部符号   __imp__glBegin @ 4 GLWindow.obj soundCube错误12错误LNK2001:未解决   外部符号   __imp__glColor4f @ 16 GLWindow.obj soundCube   错误13错误LNK2001:未解决   外部符号   __imp__glPopMatrix @ 0 GLWindow.obj soundCube错误14错误LNK2001:未解决   外部符号   __imp__glPushMatrix @ 0 GLWindow.obj soundCube错误15错误LNK2001:未解决   外部符号   __imp__glRotatef @ 16 GLWindow.obj soundCube   错误16错误LNK2001:未解决   外部符号__imp__glBlendFunc @ 8

     

...

     

错误56致命错误LNK1120:55   未解决   外部C:\ Users \ Simucal \ Documents \ Downloads \ SoundCubeSrc soundCube

我在C ++方面没有经验,但我尝试正确设置GLUT,因此该项目可以链接到它。

我下载了Nate Robin's page的GLUT32库。

然后我将以下文件放在:

  • glut.h - C:\ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Include \ gl
  • glut32.lib - C:\ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ Lib
  • glut.dll - C:\ Windows \ System32

我还选择了项目 - >属性 - >链接器 - >附加依赖性 - >添加了“glut32.lib”

如果有人想看我正在使用的项目,那就是here

为了解决这些错误,我错过了什么步骤或做错了什么?

2 个答案:

答案 0 :(得分:4)

未解析的符号来自GL和GLU库。您还需要为它们添加链接库。

答案 1 :(得分:1)

它让我觉得你在混合静态和动态链接选项。我正在下载你的项目进行调查,但是你在做什么类型的编译?

我没有在项目中看到对.lib文件的引用...

我添加了库引用和LIB / INCLUDE路径:

diff --git a/soundCube/soundCube.vcproj b/soundCube/soundCube.vcproj
index 62e04c1..b71eb20 100644
--- a/soundCube/soundCube.vcproj
+++ b/soundCube/soundCube.vcproj
@@ -41,6 +41,7 @@
            <Tool
                Name="VCCLCompilerTool"
                Optimization="0"
+               AdditionalIncludeDirectories="d:\temp\glut"
                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
                MinimalRebuild="true"
                BasicRuntimeChecks="3"
@@ -60,7 +61,9 @@
            />
            <Tool
                Name="VCLinkerTool"
+               AdditionalDependencies="glut32.lib"
                LinkIncremental="2"
+               AdditionalLibraryDirectories="d:\temp\glut\GL"
                GenerateDebugInformation="true"
                SubSystem="1"
                TargetMachine="1"
@@ -114,6 +117,7 @@
                Name="VCCLCompilerTool"
                Optimization="2"
                EnableIntrinsicFunctions="true"
+               AdditionalIncludeDirectories="d:\temp\glut"
                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
                RuntimeLibrary="0"
                EnableFunctionLevelLinking="true"
@@ -132,7 +136,9 @@
            />
            <Tool
                Name="VCLinkerTool"
+               AdditionalDependencies="glut32.lib"
                LinkIncremental="1"
+               AdditionalLibraryDirectories="d:\temp\glut\GL"
                GenerateDebugInformation="true"
                SubSystem="1"
                OptimizeReferences="2"
相关问题