Recent Changes - Search:

Coding C++

Computing

Compiler

Trail Index | More | Compiler

We are using the GCC compiler suite. Check installation on your machine using

 rpm -qa | grep gcc

A typical compile only command is

  g++ -c <filename>.cc

where '-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 access 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; without it the compiler will produce an executable called a.out.

You may have to set the executable file permissions to executable yourself:

 chmod ugo+x <filename>

You can issue

 man chmod

to see the man-page of the chmod command. Producing the executable from the source in one compile and link step would be

 g++ <filename>.cc -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 -O3 -mcpu=i686 -funroll-loops -Wall -fno-implicit-templates    //
       -Weffc++ -Wold-style-cas   <filename-1>.c  .... <filename-n>.c   //
       <filename-1>.o .....  <filename-n>.o    -I ../linux-gpib/include          //
       -L../linux-gpib/  /lib -lgpib -lfl  -L$(CERNLIB)  -lpacklib -l$(LIBF77)        //
       -lnsl  -L $(STDLIBS) -lm

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 '-O3' is an instruction customising the code optimisation. The '-Wall' and '-Weffc++' customise the warning messages.

More info from

 info gcc

< Makefiles | Trail Index | Conclusion >

Edit - History - Print - Recent Changes - Search
Page last modified on April 11, 2007, at 05:38 pm