Thread: How to run windows based application in linux

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    113

    How to run windows based application in linux

    Hi,

    I am using Ubuntu 7.1 and have created a Kdevelop application of Simple Win32GUI

    application......


    When I build it , gives following error:

    /home/bargi/Window/src/window.cpp:4:21: error: windows.h: No such file or directory
    /home/bargi/Window/src/window.cpp:6: error: ‘HINSTANCE’ was not declared in this scope
    /home/bargi/Window/src/window.cpp:6: error: ‘HINSTANCE’ was not declared in this scope
    /home/bargi/Window/src/window.cpp:6: error: ‘LPSTR’ was not declared in this scope
    /home/bargi/Window/src/window.cpp:6: error: expected primary-expression before ‘int’
    /home/bargi/Window/src/window.cpp:6: error: initializer expression list treated as compound expression
    /home/bargi/Window/src/window.cpp:7: error: expected ‘,’ or ‘;’ before ‘{’ token
    Making all in src
    make[2]: *** [window.o] Error 1
    compiling window.cpp (g++)
    make[1]: *** [all-recursive] Error 1
    make: *** [all] Error 2
    *** Exited with status: 2 ***
    How can I run it. ?????

    I have googled and found that wine can be helpful ,can anybody suggest how to utilized it and what are the steps involved ????

    Thanks

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,732
    I have googled and found that wine can be helpful ,can anybody suggest how to utilized it and what are the steps involved ????
    Ya wine is a peice of software which actual encapsulates the linux machine to run your windows application on top of it. So for eample you compiled your code on windows machine and get the binary and run it on top of wine it works fine.

    ssharish

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    But to build a Windows app like that, you need the windows SDK (or some such), which is where Windows.h lives.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    You can use Dev-C++ as your Windows compiler. I have Dev-C++ installed on a Windows partition, and it's quite simple to use wine to compile programs with it.

    I'm not sure if the Dev-C++ installer can run under Linux -- I installed it from Windows -- but you ought to be able to do something like this (assuming you have wine installed):
    • Download Dev-C++ (direct link).
    • Use wine to run the Dev-C++ installer, either by double-clicking on the exe, or running it with "wine program.exe" from the command line, or make it executable with "chmod +x program.exe" and then just use "./program.exe". Come to think of it, you may have to make it executable before you can double-click it as well.
    • Install Dev-C++ wherever, but I suggest the root of your drive, so you can remember the location (in C:\Dev-C++, say).
    • Run Dev-C++ with wine. You can probably do this with:
      Code:
      ~$ cd '.wine/drive_c/Dev-C++'
      ~/.wine/drive_c/Dev-C++$ wine ./devcpp.exe
      The paths might be slightly different, I'm not sure. You can probably figure it out -- use
      Code:
      ~$ cd .wine
      ~/.wine$ find -name 'Dev-C++'
      if you have to.
    • You should be able to use Dev-C++ to compile windows programs at this time. Note that in Dev-C++ you can open files on the "Windows drive", or on your Linux file system.


    Note that you should also be able to invoke the Dev-C++ Windows compiler directly with something like
    Code:
    ~$ cat hello.c
    #include <stdio.h>
    
    int main() {
        printf("Hello, World!\n");
        return 0;
    }
    ~$ cd '.wine/drive_c/Dev-C++/Bin'
    ~/.wine/drive_c/Dev-C++/Bin$ wine ./gcc.exe ~/hello.c -o ~/hello.exe
    ~/.wine/drive_c/Dev-C++/Bin$ cd
    ~$ wine ./hello.exe
    Hello, World!
    ~$
    If you don't have wine installed . . . well, that could be a bit trickier. I suggest you look around the internet -- you'll likely find something more informative than I could type up here.

    [edit] In case I wasn't clear -- the above process installs Dev-C++ onto your Linux partition, in wine's "virtual drive". That's different from installing it onto a separate, Windows partition, which is what I did -- but I imagine it would still work. A lot of other Windows programs do. [/edit]

    You can also try mingw. It runs under Linux, and generates Windows applications. It's a lot faster than using wine because it runs under Linux natively -- however, for some reason, I can't get it to generate certain types of Windows applications; SDL programs, for example. I think it's because of what library is being used. Anyway -- you might be able to compile an ordinary windows program with it.

    For Debian, there's a package called mingw32 that installs this program automatically. (The executable is called i586-mingw32-gcc, or something long like that.) Not sure about Ubuntu.

    Why do you need to compile a Windows program under Linux, anyway? (Not that I'm suggesting you shouldn't -- I do it myself, after all.)
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by matsp View Post
    But to build a Windows app like that, you need the windows SDK (or some such), which is where Windows.h lives.

    --
    Mats
    MSVC (except Express editions) comes with windows.h build-in
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by matsp View Post
    But to build a Windows app like that, you need the windows SDK (or some such), which is where Windows.h lives.

    --
    Mats
    Even if you had the header files, and somehow acquired the libraries in a format that the ELF linker could deal with, the resulting binary is going to be ELF. You couldn't even run it natively on Windows, much less through Wine.

    You could use Kdevelop to create the project framework, then continue your development on Windows, I guess. Or you could set up some hokey cross-compiler environment. But you really should be compiling on Windows, with a Windows compiler, if you want to create Windows programs.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pthread and socket porting from Linux to Windows
    By mynickmynick in forum C Programming
    Replies: 2
    Last Post: 07-18-2008, 06:57 AM
  2. Port app from Windows to Linux
    By BobS0327 in forum Linux Programming
    Replies: 12
    Last Post: 02-12-2006, 02:35 AM
  3. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  4. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM
  5. Linux vs. windows
    By MicrosoftRep in forum Linux Programming
    Replies: 1
    Last Post: 03-20-2002, 02:42 PM