C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 01-31-2005, 09:14 AM   #1
Registered User
 
Join Date: Oct 2002
Posts: 69
<nevermind...> compiling win32 apps under linux?

hmm, seems that I answered my own question by scrolling down a few posts....

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   Reply With Quote
Old 01-31-2005, 09:44 AM   #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   Reply With Quote
Old 01-31-2005, 09:50 AM   #3
Registered User
 
Scribbler's Avatar
 
Join Date: Sep 2004
Location: Aurora CO
Posts: 266
MinGW also has a *nix port for compiling windows executables with gcc.
Scribbler is offline   Reply With Quote
Old 01-31-2005, 09:57 AM   #4
Registered User
 
Join Date: Aug 2004
Posts: 77
Quote:
Originally Posted by Scribbler
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.
Exile is offline   Reply With Quote
Old 01-31-2005, 10:03 AM   #5
Registered User
 
Scribbler's Avatar
 
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   Reply With Quote
Old 02-06-2005, 09:28 AM   #6
Registered User
 
SpEcIeS's Avatar
 
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   Reply With Quote
Old 02-07-2005, 08:22 AM   #7
Registered User
 
SpEcIeS's Avatar
 
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
This is the simple code that is being tested:
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;
}
Does anyone know how to correct this problem?
__________________
SpEcIeS
SpEcIeS is offline   Reply With Quote
Old 02-07-2005, 09:50 AM   #8
Registered User
 
Join Date: Aug 2004
Posts: 77
be sure when you compile you use the -mwindows switch

Code:
gcc source.c -mwindows
otherwise it won't link against the windows libraries.
__________________
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   Reply With Quote
Old 02-07-2005, 10:48 AM   #9
Registered User
 
SpEcIeS's Avatar
 
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)
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?
__________________
SpEcIeS
SpEcIeS is offline   Reply With Quote
Old 02-07-2005, 11:47 AM   #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
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:
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)
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.
__________________
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   Reply With Quote
Old 02-07-2005, 12:12 PM   #11
Registered User
 
SpEcIeS's Avatar
 
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   Reply With Quote
Old 02-07-2005, 12:43 PM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:27 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22