Editor emacs or xemacs ....use tab completion to see which are around emacs<tab>This is a professional level editor with sophisticated macro capabilities and C++ aware syntax highlighting Usage emacs-20.7 <filename>i.e. for emacs version 20.7. Simply play around in the editor to learn its capabilities. You may have to go to the menu <help> --- <options> ----<global font lock> to switch on the syntax highlighting Recommended editor : kate also has syntax highlighting, and is more friendly if you are accustomed to Windows. Usage kate <filename>You right click in the text window and select the highlighting style you want. Or, use vi or a related product .... this is a scary editor, but will be the fastest if you learn it well. Compiler We are using the egc compiler suite. Check installation on your machine using rpm -qa | grep gccA typical compile only command is g++ -c <filename>.ccwhere '-c' specifies compile only. The machine code translation of the source code, which is non-executable and called object code, is output as <filename>.o. It is non-executable as it does not have the code inserted for complex system functions. This is done at the link stage, you acces the standard libraries containing code for ordinary system services by deault. A typical link command would then be g++ -<filename>.o -o <filename>Here the '-o' option specifies a non-default output filename. You may have to set the executable file permissions to executable yourself. chmod ugo+x <filename>You can issue man chmodto see the man-page of the chmod command. Producing the executable from the source in one compile and link step would be g++ -<filename>.o -o <filename> To run your program, you should be able to simply type <filename>assuming this is your executable from the previous step. The compile command can get more sophisticated ..... For example g++ -g -O4 -mcpu=i686 -funroll-loops -Wall -fno-implicit-templates //Here, we specifiy paths to non-standard include files with '-I' and we specifiy paths to non-standard library files with '-L'. We specify libraries with '-l', where the 'l' replaces the 'lib' prefix on the library, and the extension is omitted. We also use system variables, where the compilation will only work if 'CERNLIB' and 'LIBF77" are defined to point to paths where the appropriate files may be found. Also, various compiler and linker switch options are set. The '-g' caused symbolic information at the link stage to be used, so that you can run the code through the xgdb debugger. The -'O4' is an instruction customising the code optimisation. The '-W' customises the warning messages. Make utility
A simple makefile consists of "rules" with the following shape: TARGET ... : PREREQUISITES ...
*Note Writing Rules: Rules. A makefile may contain other text besides rules, but a simple makefile need only contain rules. Rules may look somewhat more complicated than shown in this template, but all fit the pattern more or less. A Simple Makefile Here is a straightforward makefile that describes the way an executable file called `edit' depends on eight object files which, in turn, depend on eight C source and three header files. In this example, all the C files include `defs.h', but only those defining editing commands include `command.h', and only low level files that change the editor buffer include `buffer.h'. --------------------------------------------------------------------------------------------------------------------- edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command.c display.o : display.c defs.h buffer.h cc -c display.c insert.o : insert.c defs.h buffer.h cc -c insert.c search.o : search.c defs.h buffer.h cc -c search.c files.o : files.c defs.h buffer.h command.h cc -c files.c utils.o : utils.c defs.h cc -c utils.c clean : rm edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o ------------------------------------------------------------------------------------------------------------------- We split each long line into two lines using backslash-newline; this is like using one long line, but is easier to read. To use this makefile to create the executable file called `edit', type: makeTo use this makefile to delete the executable file and all the object files from the directory, type: make cleanIn the example makefile, the targets include the executable file `edit', and the object files `main.o' and `kbd.o'. The prerequisites are files such as `main.c' and `defs.h'. In fact, each `.o' file is both a target and a prerequisite. Commands include `cc -c main.c' and `cc -c kbd.c'. When a target is a file, it needs to be recompiled or relinked if any of its prerequisites change. In addition, any prerequisites that are themselves automatically generated should be updated first. In this example, `edit' depends on each of the eight object files; the object file `main.o' depends on the source file `main.c' and on the header file `defs.h'. A shell command follows each line that contains a target and prerequisites. These shell commands say how to update the target file. A tab character must come at the beginning of every command line to distinguish commands lines from other lines in the makefile. (Bear in mind that `make' does not know anything about how the commands work. It is up to you to supply commands that will update the target file properly. All `make' does is execute the commands in the rule you have specified when the target file needs to be updated.) The target `clean' is not a file, but merely the name of an action. Since you normally do not want to carry out the actions in this rule, `clean' is not a prerequisite of any other rule. Consequently, `make' never does anything with it unless you tell it specifically. Note that this rule not only is not a prerequisite, it also does not have any prerequisites, so the only purpose of the rule is to run the specified commands. Targets that do not refer to files but are just actions are called "phony targets". How `make' Processes a Makefile By default, `make' starts with the first target (not targets whose names start with `.'). This is called the "default goal". ("Goals" are the targets that `make' strives ultimately to update. *Note Arguments to Specify the Goals: Goals.) In the simple example of the previous section, the default goal is to update the executable program `edit'; therefore, we put that rule first. Thus, when you give the command: make`make' reads the makefile in the current directory and begins by processing the first rule. In the example, this rule is for relinking `edit'; but before `make' can fully process this rule, it must process the rules for the files that `edit' depends on, which in this case are the object files. Each of these files is processed according to its own rule. These rules say to update each `.o' file by compiling its source file. The recompilation must be done if the source file, or any of the header files named as prerequisites, is more recent than the object file, or if the object file does not exist. The other rules are processed because their targets appear as prerequisites of the goal. If some other rule is not depended on by the goal (or anything it depends on, etc.), that rule is not processed, unless you tell `make' to do so (with a command such as `make clean'). Before recompiling an object file, `make' considers updating its prerequisites, the source file and header files. This makefile does not specify anything to be done for them--the `.c' and `.h' files are not the targets of any rules--so `make' does nothing for these files. But `make' would update automatically generated C programs, such as those made by Bison or Yacc, by their own rules at this time. After recompiling whichever object files need it, `make' decides whether to relink `edit'. This must be done if the file `edit' does not exist, or if any of the object files are newer than it. If an object file was just recompiled, it is now newer than `edit', so `edit' is relinked. Thus, if we change the file `insert.c' and run `make', `make' will compile that file to update `insert.o', and then link `edit'. If we change the file `command.h' and run `make', `make' will recompile the object files `kbd.o', `command.o' and `files.o' and then link the file `edit'. Variables Make Makefiles Simpler In our example, we had to list all the object files twice in the rule for `edit' (repeated here): ------------------------------------------------------------------------------------------------------------------- edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o ------------------------------------------------------------------------------------------------------------------- Such duplication is error-prone; if a new object file is added to the system, we might add it to one list and forget the other. We can eliminate the risk and simplify the makefile by using a variable. "Variables" allow a text string to be defined once and substituted in multiple places later (*note How to Use Variables: Using Variables.). It is standard practice for every makefile to have a variable named `objects', `OBJECTS', `objs', `OBJS', `obj', or `OBJ' which is a list of all object file names. We would define such a variable `objects' with a line like this in the makefile: ------------------------------------------------------------------------------------------------------------------- objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o ------------------------------------------------------------------------------------------------------------------- Then, each place we want to put a list of the object file names, we can substitute the variable's value by writing `$(objects)' (*note How to Use Variables: Using Variables.). Here is how the complete simple makefile looks when you use a variable for the object files: ------------------------------------------------------------------------------------------------------------------- objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o edit : $(objects) cc -o edit $(objects) main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command.c display.o : display.c defs.h buffer.h cc -c display.c insert.o : insert.c defs.h buffer.h cc -c insert.c search.o : search.c defs.h buffer.h cc -c search.c files.o : files.c defs.h buffer.h command.h cc -c files.c utils.o : utils.c defs.h cc -c utils.c clean : rm edit $(objects) ------------------------------------------------------------------------------------------------------------------- Hello World Program /************************************************************************* * Program Name : Helloworld Written by : S.H.Connell * *************************************************************************/ /**************************** * Include files * ****************************/ #include <iostream.h> /************************************************* * Function : main * *************************************************/ int main(void) { cout << "\n\n Hello World \n\n " ; return 0; } --------------------------------------------------------------------------------------------- Makefile (You will have to put in the tabs yourself if you cut and paste this code segment) --------------------------------------------------------------------------------------------- CC = g++ CFLAGS= -I. -Wno-deprecated NRLIBS=-lm # Use -O if you trust your optimizer, and # -g to make a debugging version of this library all : helloworld helloworld: helloworld.o $(CC) $(CFLAGS) -o $@ $^ $(NRLIBS) helloworld.o : helloworld.cpp $(CC) $(CFLAGS) -c $< clean: -rm -f *.o *~ .*~ core .\#* realclean: -rm -f *.o *~ .*~ core .\#* -rm -f helloworld --------------------------------------------------------------------------------------------- |