468,491 Members | 1,962 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

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.
Nov 30 '07 #1
17 5476
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
Nov 30 '07 #2
where do i press <ctrl>+F9
Nov 30 '07 #3
Ganon11
3,652 Expert 2GB
Using cygwin, type:

Expand|Select|Wrap|Line Numbers
  1. g++ yourProgramNameHere.cpp -o yourExeNameHere.exe
For a C program,

Expand|Select|Wrap|Line Numbers
  1. gcc yourProgramNameHere.c -o yourExeNameHere.exe
Make sure you're in the folder with your program file.
Nov 30 '07 #4
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
Nov 30 '07 #5
sicarie
4,677 Expert Mod 4TB
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).
Nov 30 '07 #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).
I have an error though. It says bash: gcc: command not found.
Nov 30 '07 #7
sicarie
4,677 Expert Mod 4TB
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.
Nov 30 '07 #8
where do i install it.
Nov 30 '07 #9
sicarie
4,677 Expert Mod 4TB
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.
Dec 1 '07 #10
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
Dec 1 '07 #11
sicarie
4,677 Expert Mod 4TB
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...)
Dec 1 '07 #12
cant i just use dev c++ to compile.
Dec 1 '07 #13
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.
Dec 1 '07 #14
sicarie
4,677 Expert Mod 4TB
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.
Dec 1 '07 #15
how do i put the path in the enviroment variables?
Dec 1 '07 #16
oler1s
671 Expert 512MB
how do i put the path in the enviroment variables?
We could tell you the answer to this question. But you're turning into a help vampire. Look, whether or not you realize this, you can't keep running back to us everytime you don't know something. Googling something takes about 5 seconds. Reading the material you get from Google takes a bit of work.

As a programmer, you need to be able to actively solve problems, Googling, reading material, reading books, etc. as needed. Get some practice now. If we say something, and you don't understand how to do what we ask, Google first, read the material, and try it.

See definition of help vampire. Also see article on asking smart questions.
Dec 1 '07 #17
sicarie
4,677 Expert Mod 4TB
That and the fact that this will be the second time I am telling you that it is posted above.
Dec 1 '07 #18

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by Brian | last post: by
17 posts views Thread by newbiecpp | last post: by
5 posts views Thread by Brice Prunier | last post: by
10 posts views Thread by Bart Goeman | last post: by
4 posts views Thread by John Smith | last post: by
1 post views Thread by 张沈鹏 | last post: by
2 posts views Thread by BruceWho | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.