www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D, SDL, and MacOS X

reply daerid <daerid gmail.com> writes:
I don't know whether this is something that should be addressed here, or if it
should be addressed with 
the maintainers of SDL.

Anyway, whenever I link libSDLmain.a to my D application, I all of a sudden
can't call the new operator 
anymore.

Sample code (main.d):
------------------------------------------------
class Test {}

extern (C) int SDL_main(int argc,char** argv)
{
Test t = new Test();
return 0;
}
------------------------------------------------

build command:

% gdc -L/opt/local/lib -lSDLmain -lSDL main.d -framework Cocoa -o main

It builds fine, but when I run the main executable, I get a "Bus Error". 
If I comment out the line:

Test t = new Test();

and replace it with:

printf("Hello World!\n");

then when I run it I get the expected "Hello World!" output.

Normally I'd dig in to try and find out what's going on, but frankly I know
diddly squat when it comes to 
Obj-C and Cocoa.
Dec 18 2005
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
daerid wrote:

 I don't know whether this is something that should be addressed here, or if it
 should be addressed with the maintainers of SDL.
Probably both :-) SDL uses a hack to replace the main function, and their regular library doesn't work with D. GLUT uses callbacks instead of playing with macros...
 Normally I'd dig in to try and find out what's going on, but frankly I know
 diddly squat when it comes to 
 Obj-C and Cocoa.
I have a working version for Mac OS X here: http://www.algonet.se/~afb/d/ It has a patched SDLMain.m, with what you need... (you build this obj-c code into a libSDLmain_d.a) Make sure to (indirectly) call this the first thing: int main(char[][] args) { return SDL_InitApplication(args); } That helper above is in my "sdl" wrapper directory. extern(C) int SDL_main(int argc, char **argv) { // here comes the real code } HTH, --anders
Dec 19 2005
parent daerid <daerid gmail.com> writes:
Awesome! Thanks :)

In article <do5qg3$29id$1 digitaldaemon.com>,
=?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= says...
daerid wrote:

 I don't know whether this is something that should be addressed here, or if it
 should be addressed with the maintainers of SDL.
Probably both :-) SDL uses a hack to replace the main function, and their regular library doesn't work with D. GLUT uses callbacks instead of playing with macros...
 Normally I'd dig in to try and find out what's going on, but frankly I know
 diddly squat when it comes to 
 Obj-C and Cocoa.
I have a working version for Mac OS X here: http://www.algonet.se/~afb/d/ It has a patched SDLMain.m, with what you need... (you build this obj-c code into a libSDLmain_d.a) Make sure to (indirectly) call this the first thing: int main(char[][] args) { return SDL_InitApplication(args); } That helper above is in my "sdl" wrapper directory. extern(C) int SDL_main(int argc, char **argv) { // here comes the real code } HTH, --anders
Dec 19 2005