How Do I Compile My c++ program.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TurtleGuy910
    New Member
    • Aug 2007
    • 16

    How Do I Compile My c++ program.

    I am new to C++ and made my first program which looks like this:
    #include <iostream>

    using namespace std;

    int main()
    {
    cout << "Bonjour Monde!" << endl;
    return 0;
    }

    I am using dev-c++. I was wondering how do I compile using Cygwin.
  • MarshMallow
    New Member
    • Nov 2007
    • 52

    #2
    Choose "Save as",select a proper folder where to save your file to.
    Press <Ctrl> + F9 to compile your source.
    Press <Ctrl> + F10 to execute your program.
    otherwise ,in windows ,from command line,type
    gcc.exe yourprogram.c -o yourprogram.exe

    Comment

    • TurtleGuy910
      New Member
      • Aug 2007
      • 16

      #3
      where do i press <ctrl>+F9

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        Using cygwin, type:

        Code:
        g++ yourProgramNameHere.cpp -o yourExeNameHere.exe
        For a C program,

        Code:
        gcc yourProgramNameHere.c -o yourExeNameHere.exe
        Make sure you're in the folder with your program file.

        Comment

        • TurtleGuy910
          New Member
          • Aug 2007
          • 16

          #5
          Originally posted by TurtleGuy910
          I am new to C++ and made my first program which looks like this:
          #include <iostream>

          using namespace std;

          int main()
          {
          cout << "Bonjour Monde!" << endl;
          return 0;
          }

          I am using dev-c++. I was wondering how do I compile using Cygwin.
          What is the exe name. and the file is called hello.c

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            In gcc/g++ the -o option allows you to specify the name of the resulting executable file. So when you type in '-o myprog.exe' you are saying, "call the resulting executable of my program 'myprog.exe' " and that is the file you either just type in at the command line (depending on how everything is set up) or you type ./myprog.exe.

            If you do not specify the -o option, it will be named a.exe (on Cygwin) or a.out (Linux).

            Comment

            • TurtleGuy910
              New Member
              • Aug 2007
              • 16

              #7
              Originally posted by sicarie
              In gcc/g++ the -o option allows you to specify the name of the resulting executable file. So when you type in '-o myprog.exe' you are saying, "call the resulting executable of my program 'myprog.exe' " and that is the file you either just type in at the command line (depending on how everything is set up) or you type ./myprog.exe.

              If you do not specify the -o option, it will be named a.exe (on Cygwin) or a.out (Linux).
              I have an error though. It says bash: gcc: command not found.

              Comment

              • sicarie
                Recognized Expert Specialist
                • Nov 2006
                • 4677

                #8
                Originally posted by TurtleGuy910
                I have an error though. It says bash: gcc: command not found.
                You have to install it via the setup program, I don't believe it is installed by default.

                Comment

                • TurtleGuy910
                  New Member
                  • Aug 2007
                  • 16

                  #9
                  where do i install it.

                  Comment

                  • sicarie
                    Recognized Expert Specialist
                    • Nov 2006
                    • 4677

                    #10
                    Originally posted by TurtleGuy910
                    where do i install it.
                    You need to run the Cygwin setup program again and install. This is most likely wherever you installed it originally, but I make it a point to move it back to C:/Cygwin so I don't lose it. Run the setup.exe, and it keeps your currently installed packages (unless you de-select them from the list), and will install any new packages you choose.

                    I'd recommend searching your computer for the setup.exe file as it could be anywhere (most likely your desktop or 'My Documents' folder). It will have the Cygwin icon.

                    Comment

                    • MarshMallow
                      New Member
                      • Nov 2007
                      • 52

                      #11
                      Originally posted by sicarie
                      You have to install it via the setup program, I don't believe it is installed by default.
                      I think this happens because he doesn't provide the full path of the gcc command;please update the shell Path variable with the path of the directory where gcc is installed;this can be done through control panel->system->advanced->environment variables
                      otherwise,type the whole path of gcc.exe
                      for example if gcc is in C:\mytools you should type
                      C:\mytools\gcc. exe mysource.c -o mysource.exe

                      Comment

                      • sicarie
                        Recognized Expert Specialist
                        • Nov 2006
                        • 4677

                        #12
                        Originally posted by MarshMallow
                        I think this happens because he doesn't provide the full path of the gcc command;please update the shell Path variable with the path of the directory where gcc is installed;this can be done through control panel->system->advanced->environment variables
                        otherwise,type the whole path of gcc.exe
                        for example if gcc is in C:\mytools you should type
                        C:\mytools\gcc. exe mysource.c -o mysource.exe
                        This is so if you are not using Cygwin to compile (and just Dev C++). If you are using gcc/g++ inside Cygwin, you do not need to do this.

                        (Well, at least I never have...)
                        Last edited by sicarie; Dec 1 '07, 12:25 AM. Reason: Well, at least I don't

                        Comment

                        • TurtleGuy910
                          New Member
                          • Aug 2007
                          • 16

                          #13
                          cant i just use dev c++ to compile.

                          Comment

                          • TurtleGuy910
                            New Member
                            • Aug 2007
                            • 16

                            #14
                            i just found something that says

                            There doesn't seem to be a GNU make file in PATH or in dev-c++'s Bin Path. Please make surethat you have GNU make and adjust bin setting or system PATH enviroment variable and that make setting in Compiler Option contains correct filename, otherwise you will not be able to compile anything.

                            Is that the problem? How do i fix it.

                            Comment

                            • sicarie
                              Recognized Expert Specialist
                              • Nov 2006
                              • 4677

                              #15
                              Originally posted by TurtleGuy910
                              i just found something that says

                              There doesn't seem to be a GNU make file in PATH or in dev-c++'s Bin Path. Please make surethat you have GNU make and adjust bin setting or system PATH enviroment variable and that make setting in Compiler Option contains correct filename, otherwise you will not be able to compile anything.

                              Is that the problem? How do i fix it.
                              Yes, as I said, if you are using Dev C++, you must put the path in the environment variables (as specified above). However, if you can find the file through Cygwin, you don't need to do that. It's up to you.

                              Comment

                              Working...