Texas A&M Supercomputing Facility Texas A&M University Texas A&M Supercomputing Facility

Introduction to Compiling Programs

This page introduces concepts of compiling programs using the Intel compilers on eos for examples.

Source Code Files

Object Files

At times, you may need to compile a source file without a 'main' function into an object file. This is useful for compiling separately different segments of code and it is the norm for larger projects. To compile object files, invoke the compiler with these options:

    icc -c -fpic myfunc1.c myfunc2.c -o functions.o

Note that multiple .c source files or .o object files can be compiled and linked in a single command.

Run-Time Libraries

A "Run-Time Library" (RTL) is a file which consists of collections of compiled object modules and data. It is common to package object modules of functions dealing with the same type of problem into a shared library. One example is a collection of compiled mathematical functions which carry out, say vector or matrix operations.

You may write your own RTL for use with other programs. In this case, you will need to generate your RTL object file so that programs that you write later can link to this library in order to call the functions collected there. To do this, invoke the compiler with the following arguments:

    icc -fpic -shared myfunc1.o myfunc2.o  -o libmyfuncs.a

Your output file, libmyfuncs.a could also have been named libmyfuncs.so.

Note that in UNIX/Linux there are two broad types of RTLs:

1) static libraries, typically ending '.a', as in in 'libXXX.a' and 2) dynamic libraries, typically ending in '.so', as in 'in libXXX.so' (or .dylib in MacOSX or .DLL in windows)

Static RTLs are used with static linking where the linker will copy at link time the contents of the functions and data directly into the file with the resulting executable. This makes the executable files grow dramatically in size and they place high demands for computer DRAM. Static RTLs are less common and should be avoided wherever possible.

Dynamic RTLs allow the system to load the functions and data upon loading of the binary in memory or even dynamically upon request of the program itself. These result in binaries requiring much less space to store on the file system. Most importantly, the demand for DRAM is dramatically reduced since the code from the common dynamic RTLs is loaded in the host's memory ONCE and linked to the various binaries which access it as many times as the binaries themselves.

Filename Extensions

Specific file name extensions are meant to identify files with different programming language contents. See the user guide for each system for the associations between filename extensions and programming language type.