SDL compilation problems

This is a discussion on SDL compilation problems within the C Programming forums, part of the General Programming Boards category; Error occurs as shown below: Code: $bcc32.exe -b -c -tW -DWIN32 sdltest.c -lSDL -lSDLmain Borland C++ 5.6.1 for Win32 Copyright ...

  1. #1
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555

    SDL compilation problems

    Error occurs as shown below:
    Code:
    $bcc32.exe -b -c -tW -DWIN32 sdltest.c -lSDL -lSDLmain
    Borland C++ 5.6.1 for Win32 Copyright (c) 1993, 2002 Borland
    sdltest.c:
    Warning W8057 sdltest.c 13: Parameter 'argc' is never used in function SDL_main
    Warning W8057 sdltest.c 13: Parameter 'argv' is never used in function SDL_main
    
    $ilink32.exe -aa -Tpe -c sdltest.obj SDL.lib import32.lib c0w32.obj cw32.lib
    Turbo Incremental Link 5.62 Copyright (c) 1997-2002 Borland
    Error: Unresolved external 'WinMain' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER6\LIB\C0W32.OBJ
    Here's sdltest.c:
    Code:
    #include <stdio.h>
    #include <SDL.h>
    
    int main (int argc, char **argv)
    {
        if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) < 0) {
            fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
            return 1;
        }
        SDL_Quit();
    
    	return 0;
    }
    I installed SDL and then the Borland libraries from Borland.zip that came with and then put their paths in bcc32.cfg and ilink32.cfg so that they pointed to the include dir and borland library dir respectively. The SDL faq and documentation doesn't have this problem listed and the parameters on the commandline should be correct.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    Well your code looks like a console application, yet you're trying to link it as a GUI application. It expected winmain - that's in the linker message, but all you have is main.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Code:
    #include <SDL.h>
    That should be installed in
    Code:
    #include <SDL/SDL.h>
    shouldn't it?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    Yes but you're supposed to do that according to the FAQ.
    Q: I get "Undefined reference to 'SDL_main'" ...
    A: Make sure that you are declaring main() as:

    #include "SDL.h"

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

    You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code. If for some reason you need to use WinMain(), take a look at the SDL source code in src/main/win32/SDL_main.c to see what kind of initialization you need to do in your WinMain() function so that SDL works properly.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Whoops. I put mine in "SDL/SDL.h".

    And this
    You should be using main() instead of WinMain() even though you are creating a Windows application, because SDL provides a version of WinMain() which performs some SDL initialization before calling your main code.
    seems to disprove Salem's idea. Maybe you aren't linking to all the required libraries? I seem to remember that there're three of them.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    dwk: I guess it's usually that way but I haven't put the SDL dir in my include directory, I just added SDL\include to the include path.

    [edit]I have linked all the libraries like the FAQ says.
    Link the.obj files together using ILINK32 with the following options:
    -aa (Create windows app, sounds redundant, but...)
    -Tpe (Target = windows exe)
    -c (case sensitive linking, may be the default...)
    and the following additional files (order is important)

    * sdl.lib (created in step 1)
    * import32.lib
    * c0w32.obj
    * cw32.lib
    Last edited by OnionKnight; 01-07-2006 at 01:35 PM.

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    I needed libsdl.a and sdlmain.a, I think. For Dev-C++.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    I added "SDLmain.lib" after "SDL.lib" in the command line for ilink32 and now it all works. I just hope it's not an improper thing to do that will turn out to screw things up later.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems With SDL keysym
    By IdioticCreation in forum C++ Programming
    Replies: 0
    Last Post: 12-20-2007, 05:54 PM
  2. vector compilation problems
    By Scarvenger in forum C++ Programming
    Replies: 3
    Last Post: 10-18-2007, 01:22 PM
  3. Dev-C++ Compilation Problems
    By Bnchs400 in forum Tech Board
    Replies: 4
    Last Post: 10-10-2007, 07:58 AM
  4. Problems compiling this SDL app
    By Rider in forum C++ Programming
    Replies: 3
    Last Post: 03-27-2007, 12:22 PM
  5. Compilation problems in Linux
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-19-2002, 02:01 PM

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