compiling win32 apps under linux?

This is a discussion on compiling win32 apps under linux? within the Linux Programming forums, part of the Platform Specific Boards category; hmm, seems that I answered my own question by scrolling down a few posts.... I take it that this is ...

  1. #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 08:19 AM. Reason: found answer

  2. #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.

  3. #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.

  4. #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.

  5. #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).

  6. #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

  7. #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

  8. #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."

  9. #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

  10. #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."

  11. #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.
    Last edited by SpEcIeS; 02-07-2005 at 11:20 AM.
    SpEcIeS

  12. #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."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about linux compiling with GCC
    By elsheepo in forum C++ Programming
    Replies: 23
    Last Post: 03-07-2008, 10:36 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. compiling and executing issue with lcc win32
    By GanglyLamb in forum C Programming
    Replies: 10
    Last Post: 12-22-2004, 01:24 PM
  4. Compiling a C program in Linux
    By hern in forum C Programming
    Replies: 14
    Last Post: 06-28-2004, 08:33 PM
  5. Code not compiling in Linux
    By CompiledMonkey in forum C++ Programming
    Replies: 5
    Last Post: 06-22-2004, 09:06 AM

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