Bug: Compiling SDL apps

Hello !

wizard at wizardspc /tmp
$ cc testsprite.c -o testsprite.exe sdl-config --cflags --libs

wizard at wizardspc /tmp
$ mv testsprite.c testsprite.cpp

wizard at wizardspc /tmp
$ c++ testsprite.cpp -o testsprite.exe sdl-config --cflags --libs
testsprite.cpp: In function void MoveSprites(SDL_Surface*, Uint32)': testsprite.cpp:100: warning: converting toSint16’ from double' /usr/local/lib/libSDLmain.a(SDL_win32_main.o): In functionconsole_main’:
/home/wizard/code/SDL/SDL12/src/main/win32/SDL_win32_main.c:246: undefined
refer
ence to `_SDL_main’
collect2: ld returned 1 exit status

wizard at wizardspc /tmp
$

Latest unstable SDL CVS version, latest stable CYGWIN, Win XP

CU

Torsten Giebl wrote:

Hello !

wizard at wizardspc /tmp
$ cc testsprite.c -o testsprite.exe sdl-config --cflags --libs

wizard at wizardspc /tmp
$ mv testsprite.c testsprite.cpp

wizard at wizardspc /tmp
$ c++ testsprite.cpp -o testsprite.exe sdl-config --cflags --libs
testsprite.cpp: In function void MoveSprites(SDL_Surface*, Uint32)': testsprite.cpp:100: warning: converting toSint16’ from double' /usr/local/lib/libSDLmain.a(SDL_win32_main.o): In functionconsole_main’:
/home/wizard/code/SDL/SDL12/src/main/win32/SDL_win32_main.c:246: undefined
refer
ence to `_SDL_main’
collect2: ld returned 1 exit status

wizard at wizardspc /tmp
$

Latest unstable SDL CVS version, latest stable CYGWIN, Win XP

CU


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

My best guess (not having access to those particular compilers here at
work), would be that you’re getting screwed my C++ name mangling. Try
putting an extern "C" { } block around your main() in testsprite.cpp

  • Silicon

Hello !

My best guess (not having access to those particular compilers here at
work), would be that you’re getting screwed my C++ name mangling. Try
putting an extern "C" { } block around your main() in testsprite.cpp

This works, but this is not needed
with the stable SDL version. Will this change again ?

CU

Torsten Giebl wrote:

Hello !

My best guess (not having access to those particular compilers here at
work), would be that you’re getting screwed my C++ name mangling. Try
putting an extern "C" { } block around your main() in testsprite.cpp

This works, but this is not needed
with the stable SDL version. Will this change again ?

CU

This probably shouldn’t have changed in any significant way (I can’t
check at the moment – again, work hold me back here) – if it has, I’d
consider it a bug (or, at least, an issue) in CVS.

If it has been broken, I’m not familiar enough Cygwin’s build tools to
give an exact way to fix it, but my gut wants me to ask if there is any
/clean/ way to detect the difference between c and c++ and force c++
(from SDL’s .h files) to treat make SDL_main compile with C naming
conventions?

  • Silicon

If it has been broken, I’m not familiar enough Cygwin’s build tools to
give an exact way to fix it, but my gut wants me to ask if there is any
/clean/ way to detect the difference between c and c++ and force c++
(from SDL’s .h files) to treat make SDL_main compile with C naming
conventions?

Does this work?

#define main __cdecl SDL_main

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment

Hello !

#define main __cdecl SDL_main

Where should i add this ?

CU

Sam Lantinga wrote:

If it has been broken, I’m not familiar enough Cygwin’s build tools to
give an exact way to fix it, but my gut wants me to ask if there is any
/clean/ way to detect the difference between c and c++ and force c++
(from SDL’s .h files) to treat make SDL_main compile with C naming
conventions?

Does this work?

#define main __cdecl SDL_main

-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

No, it won’t work, and won’t even compile (atleast in any compiler I
have on hand, that is) – “int main(…)” would become “int __cdecl
main(…)”, which is not in the correct order for those words. Wouldn’t
work because __cdecl only affects the way the arguments are handled –
not the way C++ mangles names.

After actually looking at the source in SDL_main.h (from 1.2.9), it
seems there actually is a comment in there about having to use the
extern "C" jiggies in there:

/* The application’s main() function must be called with C linkage,
and should be declared like this:
#ifdef __cplusplus
extern “C”
#endif
int main(int argc, char *argv[])
{
}
*/

This strikes me as odd – I don’t think I’ve ever actually had to use it
before – but, then, I’ve been using different compilers than those the
original poster is – perhaps they’re smart enough to realize that since
the previous definition of SDL_main is marked extern "C" that it
should also be extern "C"d.

  • Silicon