无法编译 OpenGL Superbible 7th 示例(未解析的外部符号)

can't compile samples of OpenGL Superbible 7th (unresolved external symbol)

我正在执行 HOWTOBUILD.txt 中的步骤。我已经为 glfw 构建了必要的文件。 linker 第一次抱怨 glfw。经过搜索,我似乎需要link反对gl3wsee this link。我已经为 gl3w 生成了静态库。现在,我打开了一个新项目并包含了 include 的路径,如下图所示。

对于 linker,我 link 反对 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);

我收到 linker 错误。

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。我已经追踪到 linker 抱怨的其中一个功能(即 sb6IsExtensionSupported()),下图显示了这个函数在 sb7.h 中被调用,而其主体实际上在 sb7.cpp 中实现。

这真的正确吗?

我已经解决了这个问题。似乎有一个静态库,我必须 link 反对并升级我的显卡驱动程序。基本上,这是我完成的。

第一步:(构建 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表示调试模式。就我而言,这是导致问题的原因,因此,您需要 link 反对它。打开新项目,将路径添加到sb7 includeglfw

C++->General-> Additional Include Directories

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

对于 linker,

Linker->General->Additional Libraries Directories

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

Linker->Input->Additional Dependencies

sb7_d.lib
glfw3dll.lib
opengl32.lib
glu32.lib

结果是

非常重要的消息:

就我而言,显卡支持 OpenGL 4.1。根据readme.txt

Please note carefully: EVEN IF YOU CAN BUILD THE SOURCES FOR YOUR FAVORITE PLATFORM OF CHOICE, YOU NEED RECENT OpenGL 4.x DRIVERS TO RUN THEM. PLEASE DON'T PAN THE BOOK BECAUSE YOUR COMPUTER DOESN'T SUPPORT OpenGL 4.x. THANKS

在我的例子中,GLFW_OPENGL_CORE_PROFILE有问题,因此我需要升级显卡驱动程序。我已经下载了这个软件 opengl extension viewer,它显示了支持的 opengl 版本。我的显示器自适应是 AMD Mobility Radeon HD 5000。我访问了他们的网站并为我的显示器下载了最新的驱动程序。事实上,我的显卡现在支持 OpenGL 4.4,这是一个快照

您注意到有一个检查更新驱动程序的按钮。在我的例子中,它将我引导至损坏的 link,因此,您需要访问该网站并检查您的显示自适应的最新更新。谢谢你。