Thread: Hard time having SDL and OpenGL work together

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Hard time having SDL and OpenGL work together

    I have SDL files installed into my lib and include directories in mingw but when I go to compile my programs I get this message

    Code:
    Z:\MinGW\lib/libSDLmain.a(SDL_win32_main.o): In function `console_main':/home/hercules/public_cvs/SDL/src/main/win32/SDL_win32_main.c:217: undefined reference to `SDL_main'
    I added the libraries SDLmain, SDL.dll and mingw32 to my linker settings but I'm still getting that error.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Use [lib]SDLmain[.a] and [lib]SDL[.a]. Also try getting rid of SDL.dll.

    Also, the order of the libraries is important. If it doesn't work, try switching them around.
    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.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I have a library file called libSDL.dll.a. There is also an SDL.la file, do I need that I tried re-arranging every thing and I even copied the libraries used in the Code::blocks SDL template with no luck. In the order they have it there.
    Last edited by indigo0086; 07-04-2007 at 02:00 PM.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Okay. Well, I never actually got the SDL working properly with Dev-C++. The closest I came is this: http://dwks.theprogrammingsite.com/m...ilseas/Makewin. That is, passing "-lSDL.dll -lSDL -lSDLmain" to the command line. But it means that you have to use WinMain() instead of main(). For portability with Linux systems, I usually go
    Code:
    #ifdef WIN32
    INT STDCALL WinMain(...) {
    #else
    int main(int argc, char *argv[]) {
    #endif
    However, these days I compile my SDL programs with MinGW 3.4.2 from the command line. Here's a Makefile (I call the Windows versions Makewin, as you may have noticed, and use make.bat which calls make.exe -f Makewin) from a recent project (Sail the Seas is ancient):
    Code:
    # Makefile for snip, Windows version
    
    SDLLIBPATH = C:/Dev-C_~2/Lib
    SDLINCPATH = C:/Dev-C_~2/Include/SDL
    
    CC = gcc
    CFLAGS = -W -Wall -ansi -pedantic -O2 -I$(SDLINCPATH) -L$(SDLLIBPATH)
    CLINK = -lm -lSDL.dll -lSDL -lSDL_image -lSDL_gfx
    
    OBJ = dsfont.o graphics.o main.o menu.o
    TARGET = snip.exe
    
    # Default target: all
    all: $(TARGET)
    
    # Executable files
    $(TARGET): $(OBJ)
    	$(CC) $(CFLAGS) -s -o $(TARGET) $(OBJ) $(CLINK)
    debug: $(OBJ)
    	$(CC) $(CFLAGS) -g -o $(TARGET) $(OBJ) $(CLINK)
    
    # Source files
    dsfont.o: includes.h dsfont.h graphics.h
    graphics.o: includes.h dsfont.h graphics.h
    main.o: includes.h dsfont.h graphics.h main.h
    menu.o: includes.h dsfont.h graphics.h menu.h
    
    # Other targets
    run: $(TARGET)
    	./$(TARGET)
    runa: $(TARGET)
    	./$(TARGET) `line`
    rundebug: debug
    	gdb ./$(TARGET)
    clean:
    	-rm $(TARGET) $(OBJ)
    (It's not actually called snip, I just removed the program's real name.)

    In other words, my linker options are -lm -lSDL.dll -lSDL -lSDL_image -lSDL_gfx, or -lSDL.dll -lSDL without the extra libraries.

    With that Makefile and the command-line MinGW 3.4.2, I can use int main(int argc, char *argv[]) in Windows and Linux.

    I don't know how things would stand with the latest version of Dev-C++ (I use an old version), or Code::Blocks. I imagine my latest version would work. -lSDL.dll -lSDL.

    Anyway, try something like that and see what happens. Throw in -lSDLmain. There's only 3! + 2! + 1! = 6 + 2 + 1 = 9 possible combinations, after all.
    Last edited by dwks; 07-04-2007 at 02:12 PM.
    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.

  5. #5
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    It's still not working. Is there an alternative to using audio with opengl

  6. #6
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL and SDL
    By ThLstN in forum Game Programming
    Replies: 2
    Last Post: 08-28-2008, 06:09 AM
  2. OpenGL using SDL --> Should I or shouldn't I?
    By Devils Child in forum C++ Programming
    Replies: 12
    Last Post: 02-01-2008, 01:18 PM
  3. Replies: 5
    Last Post: 11-27-2005, 09:50 PM
  4. Widgets with OpenGL, DirectX or SDL?
    By nickname_changed in forum Game Programming
    Replies: 1
    Last Post: 09-25-2004, 11:33 PM
  5. SDL or GLUT for Opengl?
    By drdroid in forum Game Programming
    Replies: 1
    Last Post: 07-17-2003, 01:54 AM