gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 13:31:52 26 4
gpt4 key购买 nike

我正在按照 HOWTOBUILD.txt 中的步骤进行操作。我已经为 glfw 构建了必要的文件。链接器第一次提示 glfw。搜索后,似乎我需要链接到 gl3w see this link .我已经为 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

这真的是正确的吗?

最佳答案

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

第一步:(构建 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 表示 Debug模式。就我而言,这是导致问题的原因,因此,您需要针对它进行链接。打开新项目,添加路径到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->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

结果是

enter image description here

非常重要的信息:

就我而言,显卡支持 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,这是快照

enter image description here

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

关于c++ - 无法编译 OpenGL Superbible 7th 示例(未解析的外部符号),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31899973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com