PDA

View Full Version : compiling win32 apps under linux?



talz13
01-31-2005, 09:14 AM
hmm, seems that I answered my own question by scrolling down a few posts....

I take it that this (http://www.mingw.org/) is what I want?











Is there a way to compile win32 apps using linux? At work we program lots of MFC and use #include <windows>, but I'd like to be able to run linux to do my work on.

Exile
01-31-2005, 09:44 AM
No that won't work. MingW is just a port of the GCC compiler forr Windows, it still uses the Win32 API.

To my knowledge there is no way to compile a Win32 App on Linux.

Scribbler
01-31-2005, 09:50 AM
MinGW also has a *nix port for compiling windows executables with gcc.

Exile
01-31-2005, 09:57 AM
MinGW also has a *nix port for compiling windows executables with gcc.
When they are compiled are they Windows binaries or Linux binaries? Like can you copy them to a Win32 machine and expect them to run?

I didn't know such a thing existed. Thats kinda neat if it does.

Scribbler
01-31-2005, 10:03 AM
It will create a windows .exe executable. So they will run on windows, or with wine.

Here's a quick Link (http://wiki.wxwidgets.org/wiki.pl?Cross-Compiling_Under_Linux) to get you started looking for more information (the MinGW website isn't exactly intuitive sometimes).

SpEcIeS
02-06-2005, 09:28 AM
I know this might be a little off track, but I have had success compiling windows applications using wine with hutch's MASM package. The QuickEditor worked fairly well. One issue was the linking, however it was a year ago, so I would have to re-research it. But I know it did work.

It must be possible to do using windows c++ compilers. :)

SpEcIeS
02-07-2005, 08:22 AM
After reading this post I decided to install the mingw32 packages. The test HelloWorld.c MessageBox workded well, but I cannot seem to build a basic window. The linking process spits out:

/tmp/ccRECEGP.o(.text+0xc2):BasicWindow.c: undefined reference to `_GetStockObject@4'
collect2: ld returned 1 exit status
make: *** [main_program] Error 1

This is the simple code that is being tested:

#include <windows.h>

LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wc;

char szClass[] = "My Window";
char szTitle[] = "Template";

wc.cbSize = sizeof(WNDCLASSEX);
wc.hInstance = hInstance;
wc.lpszClassName = szClass;
wc.lpfnWndProc = WindowFunc;
wc.style = 0;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.lpszMenuName = NULL;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);

if(!RegisterClassEx(&wc)) return 0;

hwnd = CreateWindow(
szClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hInstance,
NULL
);

ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);

while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}

LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}

return 0;
}


Does anyone know how to correct this problem? :confused:

Exile
02-07-2005, 09:50 AM
be sure when you compile you use the -mwindows switch


gcc source.c -mwindows
otherwise it won't link against the windows libraries.

SpEcIeS
02-07-2005, 10:48 AM
Thanks for the quick reply. :)

Now... since my system is running Debian 3.1, I used synaptic to install the mingw32 packages, however it would seem that the gcc compiler does not want to respond to the -mwindows switch. :rolleyes: Perhaps it is, but the errors are more now. :confused:

The first time the application was compiled the I used a makefile that which contains the following:

NAME = BasicWindow
COMPILE = i586-mingw32msvc-gcc
OPTIONS = -L/usr/i586-mingw32msvc/lib -llibgdi32.a -I/usr/i586-mingw32msvc/include
main_program :$(NAME).c
$(COMPILE) $(NAME).c -o $(NAME).exe $(OPTIONS)

Anytime the application was compiled to the point of receiving the GetStockObject error, I was using the i586-mingw32msvc-gcc command.

Also, in the above makefile I receive an error indidcating that it cannot find the libgdi32.a library.

What do I need to do to correct these problems? :confused:

Exile
02-07-2005, 11:47 AM
It sounds like when you run just `gcc' its using the standard Linux compiler, not the MinGW compiler. You may want to try it with the -v switch (maybe its --version ?) to get the version information and be sure its the MinGW one.

You may want to give it a shot with the `i586-mingw32msvc-gcc ' command, as in:

i586-mingw32msvc-gcc source.c -mwindows

Assuming the makefile is using the right executable for the compiler you might be able to just add the -mwindows switch to the OPTIONS and get it to work:

NAME = BasicWindow
COMPILE = i586-mingw32msvc-gcc
OPTIONS = -L/usr/i586-mingw32msvc/lib -llibgdi32.a -I/usr/i586-mingw32msvc/include -mwindows
main_program :$(NAME).c
$(COMPILE) $(NAME).c -o $(NAME).exe $(OPTIONS)

Past that I'm not really sure what else could be the issue. I haven't spent a lot of time using it on Linux.

SpEcIeS
02-07-2005, 12:12 PM
Thank-you very much Exile :D Your help has made it possible. All I had to do was add the -mwindows switch to the makefile compile line.

I am not sure why it has to be there, but it works. I would think that using the i586-mingw32msvc-gcc command would know it was mwindows. Oh well. :rolleyes:

Just another note;
Why are these applications so large? When the basic window application is compiled it is 208Kb. :confused: Debug info? If so, how do you remove it?

After using upx -9 BasicWindow.exe the program ended up at 76.5Kb. Still, that is not very small. :rolleyes:

Exile
02-07-2005, 12:43 PM
Even on windows you need to include that switch. As far as I can tell it just sets up the libraries that need to be linked to. Not sure why they don't use normal linking, like -lX11 for XWindows.