Cross-compiling woes

I’ve ported a Linux application over to SDL to make life easier for the
Windows folks who want to use it. It’s a console app that produces
audio.

I have been able to cross-compile for Win32 using mingw on a Linux host,
linking against the libs provided by the SDL-devel-1.2.8-mingw32.tar.gz
archive from the libsdl website. However, because the application has
useful console output, I don’t want the stdio redirection. I’ve used
the instructions provided at http://www.libsdl.org/extras/win32/cross/
to build a fresh libSDL with the --disable-stdio-redirect flag. But
when I try to link against this library, I get the following error:

/usr/lib/gcc/i586-mingw32msvc/3.4.2/…/…/…/…/i586-mingw32msvc/lib/libmingw32.a(main.o)(.text+0xf4):
undefined reference to `_WinMain at 16’
collect2: ld returned 1 exit status

I understand that a similar error message occurs when the linking
command is incomplete or has the wrong ordering, but I don’t think
that’s the case here. I am making use of sdl-config to get the right
flags (the makefile is attached to this message).

Any ideas?

Paul

-------------- next part --------------

barebones whitenoise Makefile for MINGW

edit to fit your needs

CC = i586-mingw32msvc-gcc
SDLROOT = …/libsdl-mingw
CFLAGS = $(SDLROOT)/bin/i586-mingw32msvc-sdl-config --cflags -DWIN32_PLATFORM
LDFLAGS = -static
LIBS = -mconsole -lm $(SDLROOT)/bin/i586-mingw32msvc-sdl-config --static-libs

main targets

all: wnoise.exe

OBJECTS = filter.o plot.o whitenoise.o

wnoise.exe: $(OBJECTS)
$(CC) -o wnoise.exe $(LDFLAGS) $(OBJECTS) $(LIBS)

clean:
rm -f wnoise.exe *.o core *~

distclean: clean
rm -f Makefile configure config.h config.log config.status;
rm -rf autom4te.cache

suffixes

.c.o:
$(CC) -c $(CFLAGS) $<

arch-tag: DO_NOT_CHANGE_5f035054-5461-44d3-a4b8-4f255fe467a2

/usr/lib/gcc/i586-mingw32msvc/3.4.2/…/…/…/…/i586-mingw32msvc/lib/libmingw32.a(main.o)(.text+0xf4):
undefined reference to `_WinMain at 16’
collect2: ld returned 1 exit status

Your entry point is main(), right? I use something like this :

#ifdef WIN32
extern “C”
{

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
char* lpCmdLine, int nCmdShow)
{

// Parse command line
String sParms = lpCmdLine;
StringList lParms = sParms.split();

int nParms = lParms.getLength();
char** pParms = new (char*)[nParms + 1];

pParms[0] = new char[8];
strcpy(pParms[0], "(dummy)");

for (int i = 0; i < nParms; i++)
{
	pParms[i+1] = new char[strlen(lParms[i]) + 1];
	strcpy(pParms[i+1], lParms[i]);
}

// Do main
int nRet = main(nParms + 1, pParms);

// Cleanup
for (int i = 0; i < nParms + 1; i++)
	delete pParms[i];

delete [] pParms;

return nRet;

}

}
#endif

Your entry point is main(), right? I use something like this :

#ifdef WIN32
extern “C”
{

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
char* lpCmdLine, int nCmdShow)
{

// Do main
int nRet = main(nParms + 1, pParms);

}
#endif

OK, thanks, that does work. But should this be necessary? I thought
SDL_main worked some magic to call the right entry point across all
platforms. And I didn’t have any problems using main() with the
precompiled mingw libraries provided on the SDL website.

PaulOn Tue, Jan 18, 2005 at 02:00:05AM -0300, Gabriel wrote:

Paul Pelzl wrote:> On Tue, Jan 18, 2005 at 02:00:05AM -0300, Gabriel wrote:

Your entry point is main(), right? I use something like this :

#ifdef WIN32
extern “C”
{

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
char* lpCmdLine, int nCmdShow)
{

// Do main
int nRet = main(nParms + 1, pParms);

}
#endif

OK, thanks, that does work. But should this be necessary? I thought
SDL_main worked some magic to call the right entry point across all
platforms. And I didn’t have any problems using main() with the
precompiled mingw libraries provided on the SDL website.

I brought this up a few days ago. I’m of the opinion that stdio
redirect is a bad idea entirely; it’s awkward to disable, usually
unexpected, often unwanted and clearly outside the natural scope of the
SDL library. (Even for programs where it is reasonable to output to
files instead of stdout, it’s badly behaved; it creates the files even
if there’s nothing to put in them, cluttering up the filesystem.)

Would anyone object to a patch that added SDL_RedirectStdio() and
removed the redirection from SDLmain?


CalcRogue: TI-89, TI-92+, PalmOS, Windows and Linux.
http://calcrogue.jimrandomh.org/

Did you remember to link with SDLmain? When I’m compiling with Mingw, I
use the following linker flags:
-lmingw32 -lSDLmain -lSDL

// MartinOn Mon, 17 Jan 2005, Paul Pelzl wrote:

/usr/lib/gcc/i586-mingw32msvc/3.4.2/…/…/…/…/i586-mingw32msvc/lib/libmingw32.a(main.o)(.text+0xf4):
undefined reference to `_WinMain at 16’
collect2: ld returned 1 exit status

Yes. The linker command uses i586-mingw32msvc-sdl-config --static-libs, which
reports:
-L/home/paul/src/libsdl-mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows
-luser32 -lgdi32 -lwinmm

(Dynamic linking produces the same error.)

PaulOn Tue, Jan 18, 2005 at 08:53:49PM +0200, Martin Storsj? wrote:

Did you remember to link with SDLmain? When I’m compiling with Mingw, I
use the following linker flags:
-lmingw32 -lSDLmain -lSDL

If you are cross-compiling from the same folder you have the linux build
in (where the .o files are) then you need to ‘make clean’ before you
build for win32. I would get this problem too when I forgot to ‘make
clean’ before I did ‘sh cross-make.sh -f Makefile.win32’ (I also made
separate makefile for the win32 build to make things easier - you could
even rename .o files to .o32 for win32 compiling and then there would be
no problems)

Dunno if that helps, but when I followed:
http://libsdl.org/extras/win32/cross/

everything worked perfectly.On Tue, 2005-01-18 at 14:37 -0500, Paul Pelzl wrote:

On Tue, Jan 18, 2005 at 08:53:49PM +0200, Martin Storsj? wrote:

Did you remember to link with SDLmain? When I’m compiling with Mingw, I
use the following linker flags:
-lmingw32 -lSDLmain -lSDL

Yes. The linker command uses i586-mingw32msvc-sdl-config --static-libs, which
reports:
-L/home/paul/src/libsdl-mingw/lib -lmingw32 -lSDLmain -lSDL -mwindows
-luser32 -lgdi32 -lwinmm

(Dynamic linking produces the same error.)

Paul


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

John Josef
Wyled
Crazed Monkeys Inc www.crazedmonkeys.com

I’ve been careful to start from a clean source tree.

PaulOn Tue, Jan 18, 2005 at 03:35:05PM -0500, John Josef wrote:

If you are cross-compiling from the same folder you have the linux build
in (where the .o files are) then you need to ‘make clean’ before you
build for win32.

Problem solved. I couldn’t reach the SDL website the other day in order
to download the source, so I was building SDL using a source tarball
from the current Debian package (it looks like a CVS snapshot prior to
the 1.2.8 release). Now that the website is back up, I used the 1.2.8
release package, and everything is working fine.

PaulOn Mon, Jan 17, 2005 at 10:40:42PM -0500, Paul Pelzl wrote:

I’ve used
the instructions provided at http://www.libsdl.org/extras/win32/cross/
to build a fresh libSDL with the --disable-stdio-redirect flag. But
when I try to link against this library, I get the following error:

/usr/lib/gcc/i586-mingw32msvc/3.4.2/…/…/…/…/i586-mingw32msvc/lib/libmingw32.a(main.o)(.text+0xf4):
undefined reference to `_WinMain at 16’
collect2: ld returned 1 exit status