Thread: libSDLmain.a and -lSDLmain!?

  1. #1
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131

    libSDLmain.a and -lSDLmain!?

    Hello.

    I discovered that when in c:\cpp\lib\ (cpp is the DevC++ root dir) there is a file called libSDLmain.a and I link -lSDLmain, then it actually links to libSDLmain.a, and If I change the name to SDLmain.a in the lib directory, then it can't find the file?

    I know, that the linker finds for files with the .a extension, so -lSDLmain -> SDLmain.a and it should! find the SDLmain.a but it doesn't.

    What am I misunderstanding?

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    The linker translates -l*something* into lib*something*.a, not *something*.a. Thus libSDLmain.a is the correct name. If I say "-lhardi", it will look for a libhardi.a in the library directories.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  3. #3
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131

    libSDL.dll.a instead of libSDL.a?

    Quote Originally Posted by Cactus_Hugger
    The linker translates -l*something* into lib*something*.a, not *something*.a. Thus libSDLmain.a is the correct name. If I say "-lhardi", it will look for a libhardi.a in the library directories.

    If it translates -lSDL to libSDL.a, then why does it give an error, when I rename libSDL.dll.a into libSDLxxxx.dll.a(basically, it can't find the file it is supposed to - it should find libSDL.dll.a (which is a mistery) but I renamed the file and it can't find it).


    Maybe the linker does not convert the -lSDL to libSDL.dll.a, maybe it converts it to libSDL.a and libSDL.a itself requires the libSDL.dll.a, BUT
    when I link the file like this: c++ SDL_tester.o c:/cpp/lib/libSDL.a then it gives undefined references for all SDL functions the SDL_tester.o uses, but If I link c:/cpp/lib/libSDL.dll.a instead of libSDL.a then it gives no error. So maybe the libSDL.a does not require libSDL.dll.a afterall?

    The command is:

    C:\cpp\Projects>%c++% SDL_tester.o SDL_tester_private.res -o main.exe -mwindows
    -lmingw32 c:/cpp/lib/libSDLmain.a c:/cpp/lib/libSDL.dll.a

    It gives no errors.

    Another command:

    C:\cpp\Projects>%c++% SDL_tester.o SDL_tester_private.res -o main.exe -mwindows

    -lmingw32 c:/cpp/lib/libSDLmain.a c:/cpp/lib/libSDL.a
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x15): undefined reference to `timeBeg
    inPeriod@4'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x1d): undefined reference to `timeGet
    Time@0'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0xc1): undefined reference to `timeGet
    Time@0'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x17e): undefined reference to `timeBe
    ginPeriod@4'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x1b1): undefined reference to `timeSe
    tEvent@20' .....................

    The 3rd command:

    C:\cpp\Projects>%c++% SDL_tester.o SDL_tester_private.res -o main.exe -mwindows
    -lmingw32 -lSDLmain -lSDL

    gives no errors!

    Where's the catch!?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by hardi
    when I link the file like this: c++ SDL_tester.o c:/cpp/lib/libSDL.a then it gives undefined references for all SDL functions the SDL_tester.o uses, but If I link c:/cpp/lib/libSDL.dll.a instead of libSDL.a then it gives no error. So maybe the libSDL.a does not require libSDL.dll.a afterall?
    If it's not broke don't fix it. If you're getting no errors then why are you changing things?

  5. #5
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    Cause I think that one should understand! Not learn by heart! Please explain me, what exactly is happening.

  6. #6
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    Quote Originally Posted by hardi
    If it translates -lSDL to libSDL.a, then why does it give an error, when I rename libSDL.dll.a into libSDLxxxx.dll.a(basically, it can't find the file it is supposed to - it should find libSDL.dll.a (which is a mistery) but I renamed the file and it can't find it).
    I wasn't quite correct in my original post, my apologies. I had to look this up myself:
    For instance, when ld is called with the argument -lxxx it will attempt to find, in the first directory of its search path,

    libxxx.dll.a
    xxx.dll.a
    libxxx.a
    cygxxx.dll (*)
    libxxx.dll
    xxx.dll
    So, since libSDL.dll.a is present, it gets used. I have two files myself: libSDL.dll.a and libSDL.a. The first links dynamically, you need SDL.dll to run the program, the second (much bigger, 12MB) links statically, no DLLs required. (But you incur some license issues.)


    Quote Originally Posted by hardi
    when I link the file like this: c++ SDL_tester.o c:/cpp/lib/libSDL.a then it gives undefined references for all SDL functions the SDL_tester.o uses, but If I link c:/cpp/lib/libSDL.dll.a instead of libSDL.a then it gives no error. So maybe the libSDL.a does not require libSDL.dll.a afterall?
    If you link with libSDL.a, I would imagine that the undefined references refer not to SDL functions, but to functions inside them. Asking the linker to use libSDL.a on my system also requires me to link with various other libraries (-lwinmm, directx, etc.) that SDL requires.

    Quote Originally Posted by hardi
    C:\cpp\Projects>%c++% SDL_tester.o SDL_tester_private.res -o main.exe -mwindows
    -lmingw32 c:/cpp/lib/libSDLmain.a c:/cpp/lib/libSDL.dll.a

    It gives no errors.
    Unlike linking with libSDL.a, this one is an import library. Thus your executable doesn't need to be linked against the other libraries mentioned. (SDL.dll, however, was linked with those when it was compiled.)

    Quote Originally Posted by hardi
    C:\cpp\Projects>%c++% SDL_tester.o SDL_tester_private.res -o main.exe -mwindows

    -lmingw32 c:/cpp/lib/libSDLmain.a c:/cpp/lib/libSDL.a
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x15): undefined reference to `timeBeg
    inPeriod@4'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x1d): undefined reference to `timeGet
    Time@0'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0xc1): undefined reference to `timeGet
    Time@0'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x17e): undefined reference to `timeBe
    ginPeriod@4'
    c:/cpp/lib/libSDL.a(SDL_systimer.o)(.text+0x1b1): undefined reference to `timeSe
    tEvent@20' .....................
    Like I said above, linking with libSDL.a requires other libraries. the time* functions you see are from the Window's Multimedia library (-lwinmm)

    Quote Originally Posted by hardi
    C:\cpp\Projects>%c++% SDL_tester.o SDL_tester_private.res -o main.exe -mwindows
    -lmingw32 -lSDLmain -lSDL
    According to my first post, -lSDL would translate into libSDL.a, but that's obviously not true since you get no errors. Using the list, we see it's not libSDL.a that gets used but libSDL.dll.a.

    Sorry about the misinformation in the first post, hopefully this clears it up!
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  7. #7
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    If it searches for multiple instances of -lxxx then what will happen, when I add this command -lSDL

    and these files are in the include directory
    libSDL.a
    libSDL.dll.a
    SDL.dll.a

    Will all the files get linked? For example, if I don't want to link libSDL.dll.a and I want to link SDL.dll.a and libSDL.a, then what do I need to do? And what happens when I only use -lSDL with the files I mentioned above?

Popular pages Recent additions subscribe to a feed