![]() |
| | #1 |
| Registered User Join Date: Oct 2002
Posts: 69
| <nevermind...> compiling win32 apps under linux? I take it that this 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. Last edited by talz13; 01-31-2005 at 09:19 AM. Reason: found answer |
| talz13 is offline | |
| | #2 |
| Registered User Join Date: Aug 2004
Posts: 77
| 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. |
| Exile is offline | |
| | #3 |
| Registered User Join Date: Sep 2004 Location: Aurora CO
Posts: 266
| MinGW also has a *nix port for compiling windows executables with gcc. |
| Scribbler is offline | |
| | #4 | |
| Registered User Join Date: Aug 2004
Posts: 77
| Quote:
I didn't know such a thing existed. Thats kinda neat if it does. | |
| Exile is offline | |
| | #5 |
| Registered User Join Date: Sep 2004 Location: Aurora CO
Posts: 266
| It will create a windows .exe executable. So they will run on windows, or with wine. Here's a quick Link to get you started looking for more information (the MinGW website isn't exactly intuitive sometimes). |
| Scribbler is offline | |
| | #6 |
| Registered User Join Date: Aug 2004
Posts: 56
| 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 |
| SpEcIeS is offline | |
| | #7 |
| Registered User Join Date: Aug 2004
Posts: 56
| 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: Code: /tmp/ccRECEGP.o(.text+0xc2):BasicWindow.c: undefined reference to `_GetStockObject@4' collect2: ld returned 1 exit status make: *** [main_program] Error 1 Code: #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;
}
__________________ SpEcIeS |
| SpEcIeS is offline | |
| | #8 |
| Registered User Join Date: Aug 2004
Posts: 77
| be sure when you compile you use the -mwindows switch Code: gcc source.c -mwindows
__________________ So, do you understand everything you know about this yet? "Begin at the beginning," the King said, very gravely, "and go on till you come to the end; then stop." |
| Exile is offline | |
| | #9 |
| Registered User Join Date: Aug 2004
Posts: 56
| 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. Perhaps it is, but the errors are more now. The first time the application was compiled the I used a makefile that which contains the following: Code: 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)
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?
__________________ SpEcIeS |
| SpEcIeS is offline | |
| | #10 |
| Registered User Join Date: Aug 2004
Posts: 77
| 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: Code: i586-mingw32msvc-gcc source.c -mwindows Code: 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)
__________________ So, do you understand everything you know about this yet? "Begin at the beginning," the King said, very gravely, "and go on till you come to the end; then stop." |
| Exile is offline | |
| | #11 |
| Registered User Join Date: Aug 2004
Posts: 56
| Thank-you very much Exile 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. ![]() Just another note; Why are these applications so large? When the basic window application is compiled it is 208Kb. 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.
__________________ SpEcIeS Last edited by SpEcIeS; 02-07-2005 at 12:20 PM. |
| SpEcIeS is offline | |
| | #12 |
| Registered User Join Date: Aug 2004
Posts: 77
| 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.
__________________ So, do you understand everything you know about this yet? "Begin at the beginning," the King said, very gravely, "and go on till you come to the end; then stop." |
| Exile is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question about linux compiling with GCC | elsheepo | C++ Programming | 23 | 03-07-2008 11:36 PM |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| compiling and executing issue with lcc win32 | GanglyLamb | C Programming | 10 | 12-22-2004 02:24 PM |
| Compiling a C program in Linux | hern | C Programming | 14 | 06-28-2004 08:33 PM |
| Code not compiling in Linux | CompiledMonkey | C++ Programming | 5 | 06-22-2004 09:06 AM |