Linux, Windows and mingw32

Hi :slight_smile:

Is there any global define to know if the program is compiling
under Linux or Windows (gcc or mingw32). Something like:

#ifdef SOMETHING
do_something
#endif

The objective is define a PATH SEPARATOR (under Linux, “/”, under
Windows “\”), so that I can load images in the correct way for
each OS. (maybe is there a portable function to build paths
such as python’s os.buildpath()?)

Another question is mingw32 related. I have a small game running
perfectly under Linux. I installed mingw32+directx_headers+sdl+
sdl_image and compiled a small demo/intro I wrote under Linux.
It worked. Then I tried to compile my game, and it compiled.
BUT when I ran it, it crashed saying that compressed bmp
files were not allowed in SDL_LoadBMP (and those are THE SAME
BMP FILES THAT I’m using under Linux). I loaded all under GIMP
and saved them with no compression, and the windows version
still says the same (I’m talking about 1 800x600 image and 20
70x96 cards for a card game). Then I replaced SDM_LoadBMP for
IMG_Load (and used SDL_image) and converted all the bmp files
to PNG files. The following is quite strange: all the images
are card-0.png to card-20.png, so the code is:

for( i=0; i<NUM_CARDS; i++ )
{
sprintf( path, “card-%d.png”, i );
Temp = IMG_Load(path);
if( Temp != NULL )
{
gfxcards[i] = SDL_DisplayFormat(Temp);
SDL_FreeSurface(Temp);
}
else
{
fprintf(stderr, “Couldn’t load %s\n”, path );
exit(-1);
}
}

If I run this code, it loads EXACTLY 15 images (not the full 20)
and gives a nice error with Couldn’t load card-15.png. Then I
though that maybe card-15.png was different of the rest, so I just
copied card-0.png (that loads perfectly) as card-15, 16, 17, 18, 19
and 20. I run and I get the same results, It only loads 15 cards.
Is this a bug or a fault on my code?

And a final question: I drop SDL.dll in the directory of my program
(the executable asks for it if it’s not present), but I don’t know
if I need to include in the same directory png.dll, zlib.dll,
and sdl_image.dll, as the program does not ask for them directly
(Although I’ve included them).

Any idea of all above? :slight_smile:

PS: I never know compiling under Windows was so kind of torture :frowning:

CU!–
Refranero: “M?s vale crond en mano que Administrador de Tareas colgado.”
_O)
NoP / Compiler | @Santiago_Romero - ICQ #98602813 /\
Linux Debian 2.2 | http://escomposlinux.org/sromero - #74.821 _V

I’m not sure about the png loading, but in windows NT variants (non 9x,
though that might have changed) you can use the ‘/’ path separator. The only
time that doesn’t work (to my knowledge) is for a remote path denoted by
double slashes-- you still have to use ‘\’ for that. There might be
something in the mingw documentation about OS specific compiler constants, I
don’t know, but I thought I saw it before. Have you tried grep-ing the mingw
documentation (windows, linux, os, etc, etc)?

As for the dlls, if unsure, toss them in the system path (C:/windows or
C:/windows/system32). You won’t have to worry about if they need to be
included or not.

I’m sorry I can’t help you with the image loading, have you tried another
format? I doubt it would change anything, but it’s worth a shot.

-Jim Stapleton

| And a final question: I drop SDL.dll in the directory of my program
| (the executable asks for it if it’s not present), but I don’t know
| if I need to include in the same directory png.dll, zlib.dll,
| and sdl_image.dll, as the program does not ask for them directly
| (Although I’ve included them).

Yes, you need those too.

png.dll makes PNG files work
zlib.dll lets you uncompress things
and you need sdl_image.dll so sdl_image works

It should have complained about those missing though…On Mon, Apr 01, 2002 at 12:02:34PM +0200, Santiago Romero wrote:


‘Bagman’ is not a legitimate career choice
6AD6 865A BF6E 76BB 1FC2 | www.piku.org.uk/public-key.asc
E4C4 DEEA 7D08 D511 E149 | www.piku.org.uk wnzrf at cvxh.bet.hx (rot13’d)

On Mon, Apr 01, 2002 at 12:02:34PM +0200, Santiago Romero wrote :

And a final question: I drop SDL.dll in the directory of my program
(the executable asks for it if it’s not present), but I don’t know
if I need to include in the same directory png.dll, zlib.dll,
and sdl_image.dll, as the program does not ask for them directly
(Although I’ve included them).

Yes you need. The truth is that the additional libraries have
to be found when the application starts up. Since we know
Windows (contrary to Unices) also searches in the current
path for executeables and DLL's, it's also perfectly valid to
have them in the same directory as the application.

I also use Dependency Walker http://www.dependencywalker.com/
to make sure the right DLL is loaded (I once had a clash
where a jpeg.dll was in another path by some oracle java
thing which caused my application not to start up).

Btw, it's not a so-good idea to just copy the required DLLs
into the Windows system directory. If the user is using
another version it just get's overwritten and if somethign
has depended on this library the user is soon in trouble . .

- Markus-- 

Please always Cc to me when replying to me on the lists.
GnuPG Key: http://guru.josefine.at/~mfischer/C2272BD0.asc
"Mind if I MFH ?" “What QA did you do on it?” “the usual?” “ah… none :)”

Hi :slight_smile:

Is there any global define to know if the program is compiling
under Linux or Windows (gcc or mingw32). Something like:

#ifdef SOMETHING
do_something
#endif

Ya, what I do is check for WIN32 to detect Windows and GNUC for Linux.
Works for me. However, I don’t use mingw32, but MSVC instead, so I don’t
know if it works with mingw32 or not.

Another idea you could try is finding a project that supports the same
platforms as you are planning to, and then look at their source code to see
how they did it.

The objective is define a PATH SEPARATOR (under Linux, “/”, under
Windows “\”), so that I can load images in the correct way for
each OS. (maybe is there a portable function to build paths
such as python’s os.buildpath()?)

Not that I know of.

-Jason

----- Original Message -----
From: compiler@escomposlinux.org (Santiago Romero)
To:
Sent: Monday, April 01, 2002 5:02 AM
Subject: [SDL] Linux, Windows and mingw32

“Santiago Romero” wrote in message
news:mailman.1017655382.27519.sdl at libsdl.org

The objective is define a PATH SEPARATOR (under Linux, “/”, under
Windows “\”), so that I can load images in the correct way for
each OS. (maybe is there a portable function to build paths
such as python’s os.buildpath()?)

‘/’ works under Windows (though probably not under MacOS).

The problem with loading the cards could be caused by out-of-bounds
array access.

for( i=0; i<NUM_CARDS; i++ )

Is ‘NUM_CARDS’ 20?

{
sprintf( path, “card-%d.png”, i );

What is ‘path’? (Should by an array of at least 12 characters.)

  Temp = IMG_Load(path);

(Assuming ‘SDL_Surface *Temp;’.)

  if( Temp != NULL )
  {
     gfxcards[i] = SDL_DisplayFormat(Temp);

Is ‘gfxcards’ declared ‘SDL_Surface *gfxcards[NUM_CARDS]’? (Should
be).> SDL_FreeSurface(Temp);

  }

}


Rainer Deyke | root at rainerdeyke.com | http://rainerdeyke.com

El Mon, 01 de Apr de 2002, a las 09:54:43AM -0700, Rainer Deyke dijo:

‘/’ works under Windows (though probably not under MacOS).

Didn’t know. Thanks! :slight_smile:

The problem with loading the cards could be caused by out-of-bounds
array access.

for( i=0; i<NUM_CARDS; i++ )

Is ‘NUM_CARDS’ 20?

21 :slight_smile:

{
sprintf( path, “card-%d.png”, i );

What is ‘path’? (Should by an array of at least 12 characters.)

char path[512];

  Temp = IMG_Load(path);

(Assuming ‘SDL_Surface *Temp;’.)

Of course :slight_smile:

  if( Temp != NULL )
  {
     gfxcards[i] = SDL_DisplayFormat(Temp);

Is ‘gfxcards’ declared ‘SDL_Surface *gfxcards[NUM_CARDS]’? (Should
be).

Yes.

     SDL_FreeSurface(Temp);
  }

}

And still does not work :slight_smile:
It only loads the first 15 png files :-?

Anyway I’m changing my cards from 20 png files to a big png file
with the 20 cards on (n*card_width), I’ll test it that way.

CU and thanks a lot.–
LSD A,(HL) ; Ponemos en el acumulador el trippi al que apunta HL.
_O)
NoP / Compiler | @Santiago_Romero - ICQ #98602813 /\
Linux Debian 2.2 | http://escomposlinux.org/sromero - #74.821 _V