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

1

6

I'm following the steps in HOWTOBUILD.txt. I have the necessary files for glfw built already. For the first time, the linker is complaining about glfw. After searching, it seems I need to link against gl3w see this link. I've generated the static libs for gl3w. Now, I've opened a new project and included the path to include, see the below picture.

enter image description here

For the linker, I've linked against glfw3dll.lib gl3w.lib opengl32.lib and included their path. If I run the sample from the first chapter,

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);

I get linker errors.

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

I'm using Visual Studio 2013. I've traced one of these functions that the linker is complaining about (i.e. sb6IsExtensionSupported()), the below picture shows how this function is being called in sb7.h while its body actually is implemented in sb7.cpp.

enter image description here

Is this actually correct?

Madonia answered 9/8, 2015 at 0:53 Comment(0)
M
6

I've solved the problem. It seems there is a static library that I have to link against and upgrade my Graphics card driver. Basically, this is I've done.

Step One: (Building GLFW)

If you have the library already built, then you don't have to do so but the problem when you build the examples, you need to set the path to GLFW properly. To save your time, build GLFW as well. To do so,

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.

Step Two: (Building Samples)

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). 

Running Examples

Now in lib folder, there is sb7.lib and sb7_d.lib. _d means debug mode. In my case, this was causing the problem, therefore, you need to link against it. Open new project, add the path to sb7 include and glfw

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

For the 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

The result is

enter image description here

VERY IMPORTANT MESSAGE:

In my case, the graphics cards supports OpenGL 4.1. According the 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

In my case, there was a problem with GLFW_OPENGL_CORE_PROFILE, therefore I needed to upgrade the graphics card driver. I've downloaded this software opengl extension viewer and it shows me the supported opengl version. My display adaptive is AMD Mobility Radeon HD 5000. I've visited their website and downloaded the latest driver for my display. Indeed, my graphics card now supports OpenGL 4.4 and this is a snapshot

enter image description here

You notice there is a button for Check for update Drivers. In my case, it directs me to a broken link, therefore, you need to go the website and check for the latest update for your display adaptive. Thank you.

Madonia answered 9/8, 2015 at 9:41 Comment(3)
Why did you use this kind of paths for the linker?Rhetorical
@AliaksiejMaroz because it has sb7_d.lib and glfw3dll.libMadonia
How did you find glfw3dll.lib ? Have you downloaded this lib separately?Rhetorical

© 2022 - 2024 — McMap. All rights reserved.