compiling c,c++ programs
hey does any one know how to compile and run c,c++ programs in linux.i am confident that the gcc compiler is loaded into my system while i was installing linux.i wanna work out on c..some one help me out plz...
|
The command to compile your program is
gcc -o executablename filename.c You can also use the shorter version: gcc filename.c (it produces a.out file) |
hey i did not get it exactly.initially
i will open a new program using vi new1.c then,i write the code and compile it like this .. gcc new1.c then what is a.out?please be more specific. |
a.out is what the output executable file will be called unless you specify a name for it with the -o switch, as in Mara's example.
hw |
hey every one is being obscure in giving their replies. can you be more clear?i opened the console and
did vi dhhh.cpp then with in the vi editor,i typed the code and pressed ctrl+alt+z ,came out and then compiled gcc -o dh.out dhhh.cpp when i run the above command, i get a n error saying Code:
root@dheeraj:~# gcc -o dh.out dhhh.cpp |
Quote:
when you want to run the compiled program use the command: ./dh.out if you're using the command in the quote. also, btw, get out of root and use a user account. |
*.cpp is c++ code... so use g++
do this: g++ XXX.cpp //this compiles the code ./a.out //this is the program produced by the compile to change the output file g++ XXX.cpp > newbie ./newbie |
I don't have an idea of Ctrl+Alt+Z in Vi. I think that it would suspend the process. Ctrl+Z! So, save your file in vi by using the command :wq and then try compiling it.
My advice to newbies is that go for simple editors like pico, nano, jed intially or spend some time in reading the help for vi or emacs. If your program is hello.c, then gcc hello.c ./a.out (or) gcc hello.c -o hello ./hello If your program is a C++ program, hello.cc g++ hello.cc ./a.out (or) g++ hello.cc -o hello ./hello |
hey thanx praveenk for your reply.i have already implemented my first c++ program on my slack..
thanx all....btw i am beginning to feel vi is not a very good editor for newbies..so i will better try out .... some other editors....emacs..... |
Hey Emacs is more painful than Vi and also more powerful too. Emacs learning curve is more than that of Vi. My suggestion is that joe, jed, nano, pico are suitable for newbies.
|
All times are GMT -5. The time now is 05:35 PM. |