Question:
how to compile, execute n see the output of cpp programs in unix or linux(terminal) ?
suji
2008-08-14 05:52:35 UTC
Linux Problem
Three answers:
MRK
2008-08-14 06:02:18 UTC
To compile a C program named fred.c, say:



[bennet@sandbox test]$ gcc fred.c



(Of course, [bennet@sandbox test]$ is the prompt; you type the rest.) To compile a C++ program, say



[bennet@sandbox test]$ g++ fred.cc



The g++ command actually runs the same compiler as gcc, but with different options directing it to compile C++. (You can compile C++ programs with the gcc command if you know a bunch of obscure options to type on the command line, or you can just let g++ do it for you.)



If the compiler finds an error in your program, it will print appropriate messages; re-edit and re-compile to repair the error. If there are no problems, the compiler will produce an executable file with the not-too-obvious name a.out. This contains the translation of your program into machine language. To run the program, simply type a.out:



[bennet@sandbox test]$ a.out The program will read any input from the keyboard, and write output to the screen
koppe74
2008-08-14 06:12:33 UTC
If it's for a package (someone else made it) you'll probably want to use "make" -- probably after first running "configure".



But I'm assuming you've written a program yourself, and saved it in some file (usually with a cpp, cxx or C suffix).



If it's just a simple program just run g++ (a part of gcc -- the GNU Compiler Collection)... it's probably already installed, if not, install the C++ part of the GCC (because you almost undoubtfully already have the C part). Type something like g++ -o myprog myprog.cpp



This will compile and link the sourcecode to a ready-to-run executable.



Here myprog.cpp is the sourcefile, and the name after -o is what the executeble will be called. If you don't specify what you want the execuatble to be called, it will be called a.out



The executable (myprog) should already have the x (executable) permission set, if not, type: chmod a+x myprog



To run your program type: ./myprog



You need the ./ first to force linux to run an executable not in the normal search PATH for executables. Usually a user *will not* put the current-directory (.) in his searchpath -- and if he does, he'll put it in the end. root should *never* have current-directory (.) in his searchpath.
?
2016-10-12 07:15:23 UTC
Notepad++ is in simple terms a code editor, that's not an IDE as such. in case you choose for to convey mutually the data, you will ought to install writing a makefile, and use the compiler from the command line. or in case you do not decide for to apply makefiles, then in simple terms form something like here, i'm undecided which compiler you're utilising, so which you will ought to locate the suitable ideas for yours. If i exchange into utilising gcc (g++) i could form something like here g++ -Wall -o programout matrice.h matrice.cpp substantial.cpp that could convey mutually it from the command line. in case you're on living house windows, which you need to to get the Borland 5.5 command line compiler (that's unfastened in case you sign up at their internet site).


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...