Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

OpenGL-SDL Unresolved External Symbol

  1. Jul 6, 2014 #1

    TheDemx27

    User Avatar
    Gold Member

    Hello.

    I am trying to get OpenGL working on my machine using SDL and glew. I've created a class 'Display' that pretty much just sets up the display and provides a place to draw things. I have 11 errors. In the errors it references both constructor and destructor in the Display class. Here is an example of an error:

    Error 1 error LNK2019: unresolved external symbol _SDL_CreateWindow referenced in function "public: __thiscall Display::Display(int,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Display@@QAE@HHABV? $basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) C:\Users\Demx\documents\visual studio 2013\Projects\OpenGLProject\OpenGLProject\Display.obj OpenGLProject

    I cannot make out head nor tail of anything coming after the reference to Display::Display(int, int etc.) If anyone can interpret some of that I would be grateful.

    Here is the complete project:
    https://github.com/TheDemx27/OpenGL-Bootstrap/tree/master/OpenGLProject [Broken]

    Thanks.
     
    Last edited by a moderator: May 6, 2017
  2. jcsd
  3. Jul 7, 2014 #2
    Haven't ever programmed in openGL. BUT that error looks like its a linker error.
    I'd check through the documentation to see if you need to link in any external dll's or lib files.
     
  4. Jul 8, 2014 #3

    chiro

    User Avatar
    Science Advisor

    Make sure you include the compiled library file within the linker properties as hinted above.

    Also make sure that you have the library that matches the header used to define the function if you have multiple builds.
     
  5. Jul 9, 2014 #4

    TheDemx27

    User Avatar
    Gold Member

    Yes I've linked the files and included SDL2.dll in the debug folder for dynamic linking.
    Confining myself to just SDL, I've followed these instructions exactly, the files are in place and I've linked them as instructed. Simply including the file has created trouble building.
    Code (Text):
    #include <SDL2/SDL.h>

    int main(int argc, char *argv[])
    {

        return 0;
    }
    Is returning a linking error. Hopefully I'm just missing something really obvious, but I've been looking at this for 2 days and I still can't figure out what I'm doing wrong.
     
  6. Jul 9, 2014 #5

    chiro

    User Avatar
    Science Advisor

    You don't include the DLL file - that is the compiled library code file.

    You have to link the lib file (ie, something like SDL2.lib) which is for the linker itself.

    If you are using a DLL, then usually what happens is that you call LoadLibrary to load the DLL
    and then you get the procedure address (I think it's GetProcAddress or something similar) and then
    you save the pointer and call the function through casting that pointer in a specific way.

    A library file may wrap this functionality for you and if it does then it will be present in your .lib file
    that is given to you by the developer.

    See if you can search for all .lib files within the SDK and see what ones are available.
     
  7. Jul 9, 2014 #6

    AlephZero

    User Avatar
    Science Advisor
    Homework Helper

    No you didn't. You included <SDL2/SDL.h>. The "SDL 101" demo says #include "SDL.h".

    Most likely, SDL.h includes some more include files which can't be found the way you did it. Did you follow the instruction
    "Add the SDL include directory to your list of includes..." or did you just try to fix the problem by including <SDL2/SDL.h>?

    It seems strange that you are getting "a linking error" here since the program shouldn't be trying to include anything! The actual error message might be more useful than your attempt at interpreting it.
     
  8. Jul 10, 2014 #7

    TheDemx27

    User Avatar
    Gold Member

    I didn't use the best choice of words. I placed the SDL.dll in the project directory as per instructions.

    I already have.

    This functionality is present in the lib file as you say.

    I don't quite know what you mean by search. I'm just using visual studio.
    Thanks for responding.
     
    Last edited: Jul 10, 2014
  9. Jul 10, 2014 #8

    TheDemx27

    User Avatar
    Gold Member

    True, it wasn't exactly, but it was an attempt to make things a bit more organized, being in a sub-directory doesn't change anything as long as the paths referenced are ok relative to that file. I tried it without the sub-directories just for the sake of getting this thing working and it gives the same linker messages.

    SDL.h should have no problem referencing the other header files. And it doesn't have any problem, since Intellisense suggests the various .h files as I type them.
     
    Last edited: Jul 10, 2014
  10. Jul 10, 2014 #9

    From what I can tell you created an object class called Display (or there is one inside of OpenGL that you are instantiating). What the error is saying is the constructor for the Display object is trying to call a function _SDL_CreateWindow which is external to the object. The linker is saying that this function does not exist in the complied and linked object.

    Try following http://www.opengl.org/wiki/Tutorial1:_Creating_a_Cross_Platform_OpenGL_3.2_Context_in_SDL_(C_/_SDL [Broken])
    it calls that function directly you might be able to narrow down what you are missing :D
     
    Last edited by a moderator: May 6, 2017
  11. Jul 10, 2014 #10

    TheDemx27

    User Avatar
    Gold Member

    Well the problem with simply writing include <SDL.h> is that SDL.h includes SDL_main.h which has the definition
    Code (Text):

    /*In file SDL_main.h*/
    #define main SDL_main
     
    Which conflicts with my main function. If I comment out the above line I can compile, but I can't call any functions at all.
    I have no idea what to do.:cry:
     
  12. Jul 10, 2014 #11
    take a look at these see if they help

    http://stackoverflow.com/questions/11976084/why-sdl-defines-main-macro
    http://www.cplusplus.com/forum/general/11692/

    or this from http://forums.libsdl.org/viewtopic.php?p=37460&sid=3374c819e18df779e17b4ce5a49fdd15
     
  13. Jul 10, 2014 #12

    TheDemx27

    User Avatar
    Gold Member

    Well, as soon as I #define SDL_MAIN_HANDLED, I can compile, but as soon as I call SDL_SetMainReady(), it still give me a linker error for that function.

    Error 1 error LNK2019: unresolved external symbol _SDL_SetMainReady referenced in function _main C:\Users\Demx\Documents\Visual Studio 2013\Projects\OpenGLProject\OpenGLProject\main.obj OpenGLProject

    As far as I can tell by looking at SDL_main.h, #defining SDL_MAIN_HANDLED is analogous to my commenting out #define main SDL_main in this situation.
     
  14. Jul 10, 2014 #13

    TheDemx27

    User Avatar
    Gold Member

    Of course perhaps that was because it was expecting WinMain now that I'm defining SDL_MAIN_HANDLED, so that could be the right way to go. The official SDL documentation has this to say about WinMain
    So I looked through the source code and found this:
    Code (Text):
    /* This is where execution begins [windowed apps] */
    #ifdef _WIN32_WCE
    int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
    #else
    It looked ok to me, so I slapped that on my main.cpp, and now I'm just getting stuck on this one error:
    Code (Text):
    Error   1   error C2731: 'WinMain' : function cannot be overloaded  c:\users\demx\documents\visual studio 2013\projects\openglproject\openglproject\main.cpp    8   1   OpenGLProject
     
    Which I might be able to solve myself. I sure hope this is the end of it. :biggrin:
     
  15. Jul 11, 2014 #14
    lol hopefully you get this all fixed up!
    I know my biggest problems when I run into errors that don't have an immediately clear solution is that I don't actually stop to think about WHY the problem is occurring, and WHAT the behavior is telling me about what is going on.

    This week I was working with a development framework which I hadn't touched in a few years, and long story short all the classes are sub classes of a std class. Then you overload custom functions in your sub class for the functionality.
    So I do this set up my custom function and it doesn't run, I then spend a couple hours confused as #*!# as to what was going on. Ended up that I had the } closing the sub class before I put in my custom functions (so they were global functions instead of class functions) /facepalm
     
  16. Jul 11, 2014 #15

    TheDemx27

    User Avatar
    Gold Member

    Well that still didn't work and I'm pretty much done with this. I've got GLFW working instead and I'm going to use that. Thanks cpscdave for your help though!

    Edit:
    And so life is good. :approve:
     
    Last edited: Jul 11, 2014
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: OpenGL-SDL Unresolved External Symbol
  1. OpenGL for physics (Replies: 6)

Loading...