Compiling and running



What is compiling ?
In most cases, the programs you write are not in a format the computer can understand and execute. Therefore, the code has to be translated, compiled. In that respect, compilers are the translators in the human-computer interface.
Compiling might consist of two parts:
  • First, the code contained in individual files is translated. During this step, the compiler creates so-called "object-files". They usually have the form "name.o" whereas the "code-files" usually are of the form "name.C" or similar.
  • Then, the various objects are connected with each other yielding the executable file, i.e. the running program.

C and C++ compilers
C and C++ compilers are for example

gcc, g++, xlc


Simple compilation
  • If you have only one file "name.C" you might type

    g++ name.C

    The compiler will produce an executable with the name a.out or similar then. In case, you're not happy with this name a.out, try

    g++ -o name name.C

    Then the name of the executable will be "name". Similarly you could use a two-step process as indicated above. Then you type first

    g++ -c name.C

    so that the compiler produces an object-file name.o. To turn this (and others) into a common executable, use something along the lines of

    g++ -o name name1.o name2.o name3.o


    Simple running
    For the running, just type the name of you executable.

    [top] [next]