Like Tree1Likes
  • 1 Post By Lesshardtofind

SDL extension

This is a discussion on SDL extension within the C++ Programming forums, part of the General Programming Boards category; I finally have some free time and decided to continue learning how to program. I got this from Lazyfoo tutorial ...

  1. #1
    Registered User LAURENT*'s Avatar
    Join Date
    May 2012
    Posts
    32

    SDL extension

    I finally have some free time and decided to continue learning how to program. I got this from Lazyfoo tutorial but I'm not sure if I get it. Could I get further instruction on the bolded part.

    When I build I always get this error.
    fatal error LNK1561

    Every extension libary has 3 essential parts:

    1. The header file.
    2. The lib file.
    3. The *.dll file(s)

    They're all set up pretty much the same way no matter which extension you're setting up.

    Open up the zip archive and there should be a folder inside.
    Open the folder and it'll contain 2 subfolders.

    2)First, open the include subfolder in the archive and you should see a header file. Put that header file in the directory with all the other header files in the SDL folder you extracted in lesson 1.

    For example, I extracted the SDL version 1.2.12 folder to "C:\", so I put the SDL_image.h (or SDL_ttf.h or SDL_mixer.h) header in C:\SDL-1.2.12\include\.

    3)Now find the lib folder from the archive. Take the library file(s) from the archive and put them with the rest of the SDL library files. In my case the rest of the SDL library files were in C:\SDL-1.2.12\lib\.

    For certain versions of SDL_image, there will be a x86 folder and a x64 folder inside of the lib folder from the archive. The x86 folder contains the 32bit *.lib files and the x64 bit folder contains the 64bit versions of the library files. If you're compiling a 32bit program, copy the library file(s) from the x86 folder and if you're compiling a 64bit version copy the library file(s) from the x64 folder. By default Visual Studio compiles in 32bit so if you're not sure how you're compiling, try the 32bit libraries first. What matters here is not whether you have 32/64bit windows, but what type of program you're compiling.

    If you don't see a x86 or x64 folder inside of the lib directory from the archive, just copy the library file(s) from the lib folder from the archive.

    4)Now extract all of the *.dll file(s) from the archive and put them in the same directory as your exe.

    Like before, you can copy them to C:\WINDOWS\SYSTEM32 (or C:\Windows\SysWOW64 on 64bit Windows) so your SDL app will find the *.dll(s) even if they're not in the same directory. The problem with this method is if you have multiple SDL apps that use different versions of SDL, you'll have version conflicts. If you have an old version in SYSTEM32 when the app uses the new version you're going to run into problems. Generally you want to have your the *.dll(s) in the same directory as your executable developing and you'll always want to have *.dll(s) in the same directory as the exe when distributing your app.

    5)Now open up your SDL project and go to the project properties.

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Copy and paste SDL.dll into the folder that your project is in.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409
    The program should build without a dll - it is a runtime dependancy - so the problem is something else
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  4. #4
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    I thought my compiler threw errors when SDL.dll wasn't in the project directory if I was trying to compile and run. If you copy and past the link error in google a few pages come up that say add SDL.dll to your directory to make it go away. There is also a couple that say its the linkerer parameters. I would have suggested that as well, but the OP seemed to highlight the part they didn't understand which also related to the error so I just made an assumption (which is usually wrong lol) and went for the SDL.dll as being the error.

    If its not the .dll then step 5 needs to be in bold. I remember the first time I tried SDL it took me literally 3-4 hours to finally get it to work. That was my first lesson in linkers lol.

  5. #5
    Registered User LAURENT*'s Avatar
    Join Date
    May 2012
    Posts
    32
    This is my code. I copy and pasted two files into my project. SDL.dll, and SDL_image.dll are with my vcxpro files. I got this error.

    Also:
    I'm using Visual Studio

    ------ Build started: Project: SDL.Lesson4, Configuration: Debug Win32 ------
    Build started 12/21/2012 9:24:27 PM.
    InitializeBuildStatus:
    Touching "Debug\SDL.Lesson4.unsuccessfulbuild".
    ClCompile:
    Main.cpp
    SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol _SDL_main referenced in function _main
    C:\Documents and Settings\Owner\My Documents\SDL.Lesson4\Debug\SDL.Lesson4.exe : fatal error LNK1120: 1 unresolved externals



    Code:
    #include"SDL_image.h"
    #include<string>
    SDL_Surface *load_image( std::string filename ) 
    {
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;
    
    //Load the image using SDL_image
    loadedImage = IMG_Load( filename.c_str() );
    
    //If the image loaded
    if( loadedImage != NULL )
    {
    
    //Create an optimized image
    optimizedImage = SDL_DisplayFormat( loadedImage );
    
    //Free the old image
    SDL_FreeSurface( loadedImage );
    }
    
    //Return the optimized image
    return optimizedImage;
    }
    
    Did I miss anything?

  6. #6
    Your imaginary friend
    Join Date
    Jan 2010
    Location
    Canada
    Posts
    76
    Did you only place the dlls in the folder, or did you also add the search directories of where you placed the actual headers into your linker?

  7. #7
    Registered User LAURENT*'s Avatar
    Join Date
    May 2012
    Posts
    32
    Quote Originally Posted by jerimo View Post
    Did you only place the dlls in the folder, or did you also add the search directories of where you placed the actual headers into your linker?
    Yeah I think so. I put the dlls files from the SDL entension in my project with the vcxpro files. I also put the dlls file with native SDL library in lib>x84. This is what I'm trying to attempt from this tutorial.

    I'm not sure what you mean by search directories.

    Lazy Foo' Productions

  8. #8
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    SDLmain.lib(SDL_win32_main.obj) : error LNK2019: unresolved external symbol _SDL_main referenced in function _main
    Most likely case SDL requires you to declare your main like.

    Code:
    int main(int argc, char*argv[])
    
    int main(int argc, char**argv)
    if your main isn't declared as such then SDL.h can't resolve its task to rename your main to SDL_main and it reports things back like "unresolved external symbol"

    The fact that SDLmain.lib shows up in the error tells me that your compiler is accessing it so the unresolved symbol error seems most likely to be the root of this issue.

    PS. The second most hit solution to this on google is making sure that you included SDL.h ... even came from here

    Problems Working with SDL
    Last edited by Lesshardtofind; 12-24-2012 at 12:18 AM. Reason: I need to learn to proof read
    stahta01 likes this.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    Quote Originally Posted by Lesshardtofind View Post
    ...if your main isn't declared as such then SDL.h can't resolve its task to rename your main to SDL_main and it reports things back like "unresolved external symbol"...
    Disgusting. Why do libraries think they can away with stuff like this? All for convenience?
    Remind me to avoid SDL if I can.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Quote Originally Posted by Elysia View Post
    Disgusting. Why do libraries think they can away with stuff like this? All for convenience?
    Remind me to avoid SDL if I can.
    Do you a suggestion for a better cross platform event handling library for OpenGL game development?

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    How about explicitly stating in the documentation that a specific initialization function shall be called or an object must be created before doing anything else with SDL?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    Quote Originally Posted by Elysia View Post
    How about explicitly stating in the documentation that a specific initialization function shall be called or an object must be created before doing anything else with SDL?
    Honestly I never noticed that. Even worse example 1.1 in the documentation shows

    Code:
    int main()
    as far as my question I genuinely wanted to know if there is a better cross-platform library for this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what an nbs extension???
    By kreyes in forum C Programming
    Replies: 3
    Last Post: 07-01-2010, 09:12 AM
  2. .ef file extension
    By xddxogm3 in forum Tech Board
    Replies: 8
    Last Post: 02-08-2006, 05:20 AM
  3. Help with PHP extension compilation
    By SkinneyEd in forum C++ Programming
    Replies: 1
    Last Post: 01-10-2006, 03:08 PM
  4. Language extension
    By Prelude in forum Contests Board
    Replies: 48
    Last Post: 06-25-2004, 06:21 AM
  5. include's extension
    By whackaxe in forum C++ Programming
    Replies: 4
    Last Post: 04-18-2004, 06:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21