Thread: Running The HelloWorld App in Windows

  1. #1
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59

    Running The HelloWorld App in Windows

    Hi guys i'm new to C, and I tried compiling the HelloWorld application.

    Code:
    #include <stdio.h>
    
    main()
    {
    
    printf("\n\nHello World\n\n");
    
    }

    In a linux environment, I compiled with the command:

    Code:
     gcc HelloWorld.c
    The file compiled successfully and I got a file, "a.out". I executed the file and it worked.

    I again compiled the file, but with the -o option, so that I could get an .exe file.

    Code:
     gcc HelloWorld.c -o HelloWorld.exe
    I then transferred HelloWorld.exe to my desktop on my windows platform, and tried to execute it in the windows environment.
    Upon execution, a terminal window popped up, and did nothing. No text was displayed.

    How do I make a windows-compatible executable? Am I missing any options to include with the compiler?
    Last edited by kwikness; 07-29-2006 at 10:42 AM.

  2. #2
    1 == 1 tzpb8's Avatar
    Join Date
    Jul 2006
    Posts
    36
    I dont know much about linux but if you write it correctly maybe it will workout so here is what you can try to compile it as:
    Code:
    #include <stdio.h>
    
    int main(void)
    {
    
    printf("\n\nHello World\n\n");
    
    return 0;
    
    }
    You can make windows executables (for xp pro atleast) with Dev-C++.
    Get it from here.
    Last edited by tzpb8; 07-29-2006 at 10:53 AM.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    If i remember correctly you can not compile something under one OS and expect it to work under another OS, unless the compiler is specifically created to do just that.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  4. #4
    Young C n00b
    Join Date
    Jul 2006
    Posts
    59
    thx Shakti, i downloaded cygwin and compiled with that. The file works in windows.

    I was under the impression that C is almost always compiled on a linux box, even if it's being designed for a windows platform.

    Does anyone know if it's possible to make a windows compatible .exe with the GCC compiler in linux?
    If so, how?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Such things are called cross-compilers.
    http://www.mega-tokyo.com/osfaq/GCC%20Cross-Compiler

    It's a fairly esoteric thing to want to do, especially since there are plenty of hosted compilers for windows anyway.

    One of the easier routes might be to run either Dev-C++ or MinGW under Wine on your Linux Box.

    > I was under the impression that C is almost always compiled on a linux box,
    > even if it's being designed for a windows platform.
    Never heard of that one before.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-22-2006, 08:45 PM
  2. Windows App a few problems
    By curlious in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2003, 04:10 PM
  3. Multiple threads, Dos APP, manage windows
    By cbrc00f in forum C Programming
    Replies: 1
    Last Post: 04-15-2003, 06:21 AM
  4. newbie question about using windows app in Dev C++
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2002, 10:50 PM
  5. Turning a Console APP into Windows.
    By Darkflame in forum C++ Programming
    Replies: 3
    Last Post: 09-14-2001, 03:10 AM