无法编译OpenGL Superbible第七版的示例代码(未解决的外部符号)

6
我正在按照HOWTOBUILD.txt的步骤进行操作。我已经构建好了glfw所需的文件。第一次,连接器报错了glfw。经过搜索,我发现需要链接到gl3w,可以参考这个链接。我已经生成了gl3w的静态库。现在,我打开了一个新项目并将路径包含在include中,如下图。

enter image description here

对于连接器,我已经链接到了glfw3dll.lib gl3w.lib opengl32.lib并包含了它们的路径。如果我运行第一章的示例,

main.cpp

#include "sb7.h"


class my_application : public sb7::application
{
    void render(double currentTime)
    {
        static const GLfloat red[] = { 1.0f, 0.0f, 0.0f, 1.0f };
        glClearBufferfv(GL_COLOR, 0, red);
    }
};


DECLARE_MAIN(my_application);

我遇到了链接器错误。

1>main.obj : error LNK2019: unresolved external symbol "int __cdecl sb6IsExtensionSupported(char const *)" (?sb6IsExtensionSupported@@YAHPBD@Z) referenced in function "public: virtual void __thiscall sb7::application::run(class sb7::application *)" (?run@application@sb7@@UAEXPAV12@@Z)
1>main.obj : error LNK2019: unresolved external symbol "private: static void __stdcall sb7::application::debug_callback(unsigned int,unsigned int,unsigned int,unsigned int,int,char const *,void *)" (?debug_callback@application@sb7@@CGXIIIIHPBDPAX@Z) referenced in function "public: virtual void __thiscall sb7::application::run(class sb7::application *)" (?run@application@sb7@@UAEXPAV12@@Z)
1>main.obj : error LNK2001: unresolved external symbol "protected: static class sb7::application * sb7::application::app" (?app@application@sb7@@1PAV12@A)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

我正在使用Visual Studio 2013。我已经追踪了链接器抱怨的其中一个函数(即sb6IsExtensionSupported())。下面的图片展示了这个函数在sb7.h中的调用方式,而它的实际实现是在sb7.cpp中完成的。

enter image description here

这样做正确吗?

1个回答

6
我已经解决了这个问题。看起来我需要连接静态库并升级我的显卡驱动程序。基本上这就是我所做的事情。
步骤一: (构建GLFW)
如果您已经构建好库,则不需要再进行此操作,但是如果在构建示例时出现问题,则需要正确设置GLFW的路径。为了节省时间,请先构建GLFW。要执行此操作,请:
1- install cmake.
2- Open the command prompt and navigate to extern/glfw-3.0.4 (using cd command)
3- Type in command prompt: cmake -G "Visual Studio 12" 
4- Open GLFW.sln and build all ( do it for Debug and Release modes)
5- Copy `glfw-3.0.4/src/Debug/glfw3.lib` into the `lib` directory and rename it to glfw3_d.lib.
6- Copy `glf3-3.0.4/src/Release/glfw3.lib` into the `lib` directory but don't rename it.

第二步:(构建样例)
1- Open the command prompt and navigate to "build" folder
2- Type in command prompt: cmake -G "Visual Studio 12" ..
3- Open superbible7.sln in build folder and build all. (do it for Debug and Release modes). 

运行示例

现在在lib文件夹中,有sb7.libsb7_d.lib_d表示调试模式。在我的情况下,这导致了问题,因此您需要链接它。打开新项目,添加路径到sb7 includeglfw

C++->常规->附加包含目录

D:\CPP_Projects\VisualStudio\Modern OpenGL\sb7code-master\sb7code-master\include
D:\CPP_Libraries\glfw-3.1.1\glfw-3.1.1\include

链接器相关,请设置以下选项:

链接器->常规->附加库目录

D:\CPP_Libraries\glfw-3.1.1\glfw-3.1.1\install\src\Debug
D:\CPP_Projects\VisualStudio\Modern OpenGL\GLFW\OpenGLSuperBible_7th\OpenGLSuperBible\ChapterOne\Debug
输入->附加依赖项>
sb7_d.lib
glfw3dll.lib
opengl32.lib
glu32.lib

结果如下:

结果为:

enter image description here

非常重要的信息:

在我的情况下,显卡支持OpenGL 4.1。根据readme.txt

请注意:即使您可以构建您选择的平台的源代码,您还需要最新的OpenGL 4.x驱动程序才能运行它们。请不要因为您的计算机不支持OpenGL 4.x而抨击本书。谢谢。

在我的情况下,出现了GLFW_OPENGL_CORE_PROFILE的问题,因此我需要升级显卡驱动程序。我下载了这个软件opengl extension viewer并显示了支持的OpenGL版本。我的显示适配器是AMD Mobility Radeon HD 5000。我访问了他们的网站并下载了我的显示器的最新驱动程序。确实,我的显卡现在支持OpenGL 4.4,这是一个快照

enter image description here

您会注意到有一个检查更新驱动程序的按钮。在我的情况下,它将我引导到了一个失效的链接,因此,您需要前往网站并查找您的显示适配器的最新更新。谢谢。


你为什么要使用这种路径来进行链接? - donutello
@AliaksiejMaroz 因为它包含 sb7_d.lib 和 glfw3dll.lib。 - CroCo
你是如何找到glfw3dll.lib的呢?你有单独下载这个库吗? - donutello

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接