[SDL] Dev C++ Linking Issues

Elden Armbrust earmbrust at xero-soft.com
Thu Sep 29 21:32:42 PDT 2005


Mike Frysinger wrote:

>On Thursday 29 September 2005 10:37 pm, Tyler Montbriand wrote:
>  
>
>>On September 29, 2005 08:03 pm, Tim Swast wrote:
>>    
>>
>>>When I try to compile even a simple program with SDL, I get the error
>>>
>>>      
>>>
>>>>[Linker error] undefined reference to `SDL_main'
>>>>        
>>>>
>>1) It has to be int main(int argc, char *argv[]), not int main().
>>SDL expects, nay, *demands* it take those two parameters.
>>
>>2) If your main is in a C++ file, chances are your 'main' function is not
>>really called 'main' as far as the linker's concerned, but
>>1502347xcgxf532189_main@ or some other garbage.  C++ mangles the names to
>>prevent overloaded functions from having the same names.
>>
>>Fortunately, there's a way to tell C++ to do that.  Try:
>>  extern "C" int main(int argc, char *argv[])
>>instead of
>>  int main()
>>    
>>
>
>this must be a VC++ thing then because linux doesnt require either of these
>-mike
>
>_______________________________________________
>SDL mailing list
>SDL at libsdl.org
>http://www.libsdl.org/mailman/listinfo/sdl
>
>  
>
Actually, it's a gcc-mingw thing (for some reason), which happens to 
occur quite frequently to the newbies (no offense intended).

Tim is right on the money about the formatting of the main() function, 
make sure it looks identical to the way he's shown.
Adding -Dmain=SDL_main to the compiler options (if my memory serves me 
well) in Dev-C++ will do the trick, along with the options already 
listed above.
Let us know if you get it working!

-Elden





More information about the SDL mailing list