Thread: How do I use Cygwin?

  1. #16
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    ok, I tried that and it said that "autoexec.bat" is not an internalized command or something. I tried opening it manually but it just opens and closes quickly.

  2. #17
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Alternatively, try this very simple example using a batch file:
    1. Create a new directory on your desktop: 'New Folder'.
    2. Create a new text file in that directory. Call it main.cpp and add, for example
      Code:
      #include <iostream>
      
      int main()
      {
      std::cout<<"hello from MinGW"<<std::endl;
      }
    3. Copy a command prompt shortcut to the 'New Folder' and put the path to 'New Folder' into the 'start in' field of the command prompt properties (right-click on cmd prompt shortcut and select properties from menu).
    4. Create a text file in 'New Folder'. Call it 'build.bat' and add the following, replacing c:\mingw\bin with the actual path to your MinGW installation bin directory:
      Code:
      set path=c:\mingw\bin;%path%
      g++ main.cpp -o test.exe
    5. Launch cmd prompt by double-clicking its shortcut in 'New Folder'. Type 'build' then enter/return. This should create 'test.exe' in 'New Folder'.
    6. Type 'test' then enter/return to run test.exe


    Compiling 'C'

    Name text file in step 2. above as main.c
    Code:
    #include <stdio.h>
    
    int main()
    {
    printf("hello from Mingw");
    }
    For step 4. the batch file should read:
    Code:
    set path=c:\mingw\bin;%path%
    gcc main.c -o test.exe
    Last edited by Ken Fitlike; 05-12-2004 at 06:58 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #18
    Registered User loopy's Avatar
    Join Date
    Mar 2002
    Posts
    172
    Quote Originally Posted by indigo0086
    ok, I tried that and it said that "autoexec.bat" is not an internalized command or something. I tried opening it manually but it just opens and closes quickly.
    I actuallty solved that (if its the same problem), last time I made a .bat file in XP, it had a .txt extention (.txt), I solved it with by messing with the file propertys in explorer, that COULD be the problem.
    WorkStation(new, a month ago):

    Sony Vaio i686 Desktop
    2.60 GIGhz Intel Pentium 4(HT)
    512Mb DDR RAM
    800MHz Front Side Bus!
    120 GIG IDE HardDrive
    Matrox G400 Dual-Head
    Linux kernel 2.6.3
    Modified Slackware 9.1
    GCC/GDB

    Multi-mon
    Simultaneous Multiple Processes

  4. #19
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Quote Originally Posted by Ken Fitlike
    Alternatively, try this very simple example using a batch file:
    1. Create a new directory on your desktop: 'New Folder'.
    2. Create a new text file in that directory. Call it main.cpp and add, for example
      Code:
      #include <iostream>
      
      int main()
      {
      std::cout<<"hello from MinGW"<<std::endl;
      }
    3. Copy a command prompt shortcut to the 'New Folder' and put the path to 'New Folder' into the 'start in' field of the command prompt properties (right-click on cmd prompt shortcut and select properties from menu).
    4. Create a text file in 'New Folder'. Call it 'build.bat' and add the following, replacing c:\mingw\bin with the actual path to your MinGW installation bin directory:
      Code:
      set path=c:\mingw\bin;%path%
      g++ main.cpp -o test.exe
    5. Launch cmd prompt by double-clicking its shortcut in 'New Folder'. Type 'build' then enter/return. This should create 'test.exe' in 'New Folder'.
    6. Type 'test' then enter/return to run test.exe


    Compiling 'C'

    Name text file in step 2. above as main.c
    Code:
    #include <stdio.h>
    
    int main()
    {
    printf("hello from Mingw");
    }
    For step 4. the batch file should read:
    Code:
    set path=c:\mingw\bin;%path%
    gcc main.c -o test.exe
    how do I create a command prompt shortcut?

  5. #20
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Just copy it from your start menu (it may be in 'accessories' or something in win2k/xp; I tend to move it into 'program files' so don't recall exactly where it's originally to be found).

    Or, perhaps easier, right-click in the 'New Folder', select 'new shortcut' from the popup menu and paste
    Code:
    %SystemRoot%\system32\cmd.exe
    into the 'type the location of the item' edit control, then click 'next' and finally 'finish'. That should create a 'cmd.exe' shortcut in win2k/winxp.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  6. #21
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    ok i found out how to do it...not as easyas my visual studio.net though.

    how do I get the program to run in a seperate window?
    Last edited by indigo0086; 05-12-2004 at 07:23 PM.

  7. #22
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>ok i found out how to do it<<

    Congratulations.

    >>...not as easyas my visual studio.net though.<<

    Which is probably why many MinGW users prefer an ide such as devcpp...

    BTW, if you're feeling particularly masochistic you should be able to use msvc in an analogous fashion from the command line, too - just search through your .net installation directory for vcvars32.bat.

    >>how do I get the program to run in a seperate window?<<

    You read this faq and this faq, add the appropriate code and launch the program separately.
    Last edited by Ken Fitlike; 05-12-2004 at 07:47 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #23
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I think i'll stick to VS.net I tried devc++ but the iostream header wasn't there and it showed errors involving them.

  9. #24
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    IMO the DevC++ package is the best available for learning to code in windows. You'll find it much easier to use and will find its probably more current to the standards that M$.

    iostream is deffinitely there.
    Are you accessing the depricieted version, <iostream.h> or <iostream> ?
    Open source isn't a matter of life or death......
    .......its much more important than that!!


    SuSE Linux - GCC 3.4.2
    XP Pro - Visual Studio 2005 TS, MinGW 3.4.2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NetBeans + Cygwin driving me insane
    By Del75 in forum C++ Programming
    Replies: 4
    Last Post: 08-17-2008, 05:03 AM
  2. cygwin sshd weird behavior
    By jEssYcAt in forum Tech Board
    Replies: 6
    Last Post: 05-19-2008, 02:05 PM
  3. Problems with compiling code in cygwin
    By firyace in forum C++ Programming
    Replies: 4
    Last Post: 06-01-2007, 08:16 AM
  4. Cygwin and coLinux
    By Mario F. in forum Tech Board
    Replies: 8
    Last Post: 07-03-2006, 02:00 PM
  5. Cygwin Server
    By osal in forum Networking/Device Communication
    Replies: 0
    Last Post: 03-07-2005, 12:58 PM