Start-up notes on Programming in C++(import in progress from http://www.src.wits.ac.za/groups/psi/linux/c/index.html by Simon Connell) Trail Index | Conclusion | Start-up notes on Programming in C++ IntroductionIf you arrived to this page first, and you are not familiar with Linux, you may want to check the Linux Introduction? first. This page focuses on how to write, compile, link and execute a C++ program in Linux, and assumes a minimum of familiarity with it. EditorsHere you will find some suggestions of programs you can use to edit source code. You can also see Writing Code for general considerations on writing source code. Katekate is a simple window-based editor that has syntax highlighting, and is more familiar if you are accustomed to Windows. kate <filename> You right click in the text window and select the highlighting style you want. Kate' has two serious drawbacks: it does not offer automatic indentation, and it is not integrated with the compiler. EmacsEmacs (or its variant XEmacs) is an advanced editor with C++ aware syntax highlighting, auto-indenting, integration with compiler, debugger and versioning, and sophisticated macro capabilities. Another advantage of Emacs is that it can also be used in a terminal window, in text mode, which is very useful if you are working on a remote host. emacs <filename> xemacs <filename>
Simply play around in the editor to learn more of its capabilities. OthersOr, use If you have used before an IDE (Integrated Development Environment) like Visual Studio, you may find yourself most comfortable with Eclipse. I would anyway note that usually IDEs are not practical for writing small pieces of code like those for data analysis. CompilerFor this tutorial we use the GCC compiler suite. You can check its installation on your Linux machine using $ rpm -qa | grep gcc Most of the examples in this tutorial can be compiled simply with a command like $ g++ helloworld.cpp -o helloworld which produces a binary executable file $ ./helloworld You can see Compiler for some background, available options and more details. Make utility and MakefilesThe You can see Makefiles for some background, available options and more details. Hello World Program
/************************************************************************* * Program Name : Helloworld Written by : S.H.Connell * *************************************************************************/ /**************************** * Include files * ****************************/ #include <iostream> /************************************************* * Function : main * *************************************************/ int main(void) { std::cout << "\n\n Hello World \n\n " ; return 0; }
CXX = g++ CC = g++ CXXFLAGS= -I. -Wall -Wno-deprecated # Use -O3 if you trust your optimizer, or # -g to make a debugging version of this program LDLIBS=-lm TARGET=helloworld all : $(TARGET) helloworld: helloworld.o clean: -rm -f *.o *~ .*~ core .\#* realclean: clean -rm -f $(TARGET) Once you have the files, you can run $ make $ ./helloworld Conclusion
|