How to compile a C program

How to compile a C program

The word compile means to translate a programming code to code executable by the machine. To compile a source code and make it executable there are different ways depending on the compiler used. Among these compilers, one of the most famous is C, and used for the bases of many programming languages.

To understand how a C program is compiled, it is important to know the different stages that are needed for the program to be executed by a user and by the computer.

No hay texto alternativo para esta imagen

This scheme can help us to enumerate the usual programming tasks. The most common task is the generation of an executable program. As the name implies, it is a file that contains code directly executable by the processor.

Based on the schemes, let's see the necessary steps to compile our program.

 

The preprocessor accepts as input source code and is responsible for:

Delete comments.

Interpret and process preprocessing directives, always preceded by the # symbol.

After this stage it becomes a readable file to perform the second step. To understand it better in our files we just wrote a program in c and save it as main.c

No hay texto alternativo para esta imagen

With the gcc -E command option, we say that only preprocess do not compile or anything like that, so our program becomes those lines of code, after that we follow the compiler to analyze the syntax and semantics of the preprocessed source code and translate it, generating a file that contains the object code.

No hay texto alternativo para esta imagen

With the gcc -c command we are saying that you compile us with the option that the new file to be output has the same name of the file to compile and that it ends with the extension .o, this command creates a new file for the assembler than what it is in itself to talk about that cool language in computer language as we will see now.

The linker groups the object modules (which often have extensions such as .o or .obj), generated by the compiler, into an executable program that the operating system can load and execute. It is the last phase of the compilation process.

No hay texto alternativo para esta imagen

With the gcc -S command we are saying that the main.o file assembles that file to be binary code.

Finally it is the use of libraries. All these functions are incorporated through a wide set of libraries that are not part, properly speaking, of the programming language. However, as indicated above, some libraries are automatically linked when generating an executable program, which leads to the error of thinking that, for example, printf () is a function of the C language


Thanks you :)


要查看或添加评论,请登录

Deiwin Ignacio M.的更多文章

  • IoT Do you really exist?

    IoT Do you really exist?

    "Internet of things" for some this set of words may sound a bit strange even without meaning while for others it is a…

  • The present is ours Machine Learning

    The present is ours Machine Learning

    To understand that and how machine learning works we must understand how a program works on a computer How does a…

  • Python a beauty of language

    Python a beauty of language

    Python is a very powerful and flexible general-purpose programming language, yet simple and easy to learn. In this…

  • ? What is dynamic library in c ?

    ? What is dynamic library in c ?

    Libraries are a set of applets used to develop software. Libraries contain code and data, which provide services to…

  • C static libraries

    C static libraries

    Before understanding that they are the static libraries, it is necessary to know that they are the libraries in…

  • What is the difference between a hard link and a symbolic link?

    What is the difference between a hard link and a symbolic link?

    LINUX (or GNU / LINUX, more correctly) is an Operating System like MacOS, DOS or Windows. That is, Linux is the…

  • What happens when you type ls *.c in the terminal the Linux

    What happens when you type ls *.c in the terminal the Linux

    Before understanding what happens when pressing ls * .c we must remember that it is Linux.

社区洞察

其他会员也浏览了