c++openglgame-engineunresolved-externalsoil

Unresolved External Symbol on SOIL2 Files - requires opengl calls


It seems that when I try and build my project it fails the build because of some unresolved external symbols from SOIL2. It doesn't know what calls like: "__imp_glTexParameteri" are. I have glfw lib in my project but it still seems to think that I don't have any references to this. I have gl calls in my project but it doesn't seem to extend to the SOIL2 lib. Is there anything I can do about this?

Is more information needed?

I have confirmed that the libs that are being run in the x64 space are x64 and the x32 libs are being run in the x32 space

1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_wglGetProcAddress referenced in function SOIL_GL_GetProcAddress
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glBindTexture referenced in function SOIL_direct_load_DDS_from_memory
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glDeleteTextures referenced in function SOIL_direct_load_DDS_from_memory
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glGenTextures referenced in function SOIL_direct_load_DDS_from_memory
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glGetError referenced in function SOIL_direct_load_ETC1_from_memory
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glGetIntegerv referenced in function SOIL_GL_ExtensionSupported
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glGetString referenced in function SOIL_GL_ExtensionSupported
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glPixelStorei referenced in function SOIL_direct_load_ETC1_from_memory
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glReadPixels referenced in function SOIL_save_screenshot
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glTexImage2D referenced in function SOIL_direct_load_DDS_from_memory
1>SOIL2.obj : error LNK2019: unresolved external symbol __imp_glTexParameteri referenced in function SOIL_direct_load_DDS_from_memory

Here is the unresolved External Symbols I am getting.


Solution

  • Takes deep breath apologizes in advance for the length of this post

    From the documentation on LNK2019 error:

    There are many ways to get this error, but all of them involve a reference to a function or variable that the linker can't resolve, or find a definition for. The compiler can identify when a symbol is not declared, but not when it is not defined, because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.

    What @xaxxon is saying is correct. The functions that the linker has generated warnings about are all OpenGL functions.

    So what these errors are telling you is that the SOIL2.obj has a dependancy on the OpenGL library.

    There are two common forms of libraries that you can link against, static libraries and dynamic libraries.

    Courtesy of Wikipedia & Technopedia:

    Static Libraries

    In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.

    Dynamic Libraries or Shared Libraries

    A dynamic library is a programming concept in which shared libraries with special functionalities are launched only during program execution, which minimizes overall program size and facilitates improved application performance for reduced memory consumption. In most software programs, distributing specific functionalities into distinct modules allows loading as needed.

    A dynamic library is never part of an executable file or application. During runtime, a link is established between a dynamic library and executable file or application.

    Linking is not an easy concept to get your head around and if you are just starting out you might want to visit Lazy Foo's site which can walk you through the basics of linking against the freeglut library.

    http://lazyfoo.net/tutorials/OpenGL/01_hello_opengl/windows/msvsnet2010u/index.php

    But the basics are; in order to use someone else's library you should first understand how that library was created. Whether the person created a static library or a dynamic library. Then you can work out how you should link against that library.

    For example when linking against a shared library you will need to include the .dll file with the executable, this is because when the program is run the "remaining" bits of linking are done "just in time" for the program to run. See: https://www.lurklurk.org/linkers/linkers.html

    I know this answer is too long and lengthy and you probably just wanted a simple: "Drag and drop this file in to x directory". Unfortunately it really does pay off if you sit down and learn exactly what things like the compiler and linker are actually doing and what they are trying to communicate to you.

    I can't give you step by step instructions on that because it's going to depend on what libraries you have.

    Howevver

    If you happen to have a project in Visual Studio you can cheat with Nuget Package Manager and install nupengl which will install OpenGL and GLEW for you.

    http://in2gpu.com/2014/11/29/setting-opengl-visual-studio-using-nuget/

    Just remember that it's not magic! It's just linking against libraries and you should really learn how to do that without Nuget. Goodluck!