News: First Steps of Compiling a Program in Linux

First Steps of Compiling a Program in Linux

This article describes the very basics of compiling a program on Linux. It is targeted at the absolute beginner. Sometimes beginners search for programs on the web for their Linux systems, and is faced with the reality that they have to compile the program themselves, either because there exists no binary for their architecture, or the author of the program just doesn't release any binaries at all, but only sources.

The reader is expected to know how directory structures work (on any platform, not linux specific), how to move files (copy and paste files with a GUI), what zipped files are, and how to download the program/files and save them in a place they know. No programming knowledge is necesary.

It is very important to read the README file that came with the source files, as this contains additional instructions specific to that program.

Step 1 Copy the files to a "working directory"

Copy the zipped (*.tar.gz, *.gzip etc) file to a temporary directory where you will do the work. On my PC it is /home/renato/temp/

Step 2 Extract the files

You can use the GUI and with your mouse, rightclick on the file, and click on "extract here" or something similar:

First Steps of Compiling a Program in Linux

or from the command line (Terminal or Console or something similar) type this command:

First Steps of Compiling a Program in Linux

Step 3 Change to the program directory

From here on we will be using the command line. Open Terminal or Console or whatever command line application you have available. On my system the directory is /home/renato/temp/naev-0.5.-1/, so I will type in the command line:

First Steps of Compiling a Program in Linux

Step 4 Generate a make file by running the configure script

We now need to generate a make file. Usually you will see a file called configure in the program's directory. If not and you see a file called "makefile", you can skip this step, this means the makefile is already created for you. Run the script with this command:

./configure

You will see a screen like follow: (Note the green "configure" script)

First Steps of Compiling a Program in Linux

This script checks that your PC has everything needed to compile this program. If you need to install additional stuff, the configure script will tell you. If no error were encountered, you will see a file called Makefile, so you can continue to the next step.

Step 5 Compile the program

Now you compile the program using a tool called make.

First Steps of Compiling a Program in Linux

After the make process is completed, you should see the executable program in your working directory. You can now run it with ./program where program is the filename of the program you just compiled.

First Steps of Compiling a Program in Linux

Step 6 Move the executable somewhere else

You can now keep the executable where it is, or you can "install" it using the command make install, which will copy it to the program directory(s), in case you want to delete this temp directory.

Conclusion

This is the basics for compiling a program from source on a Linux (or Unix like) system. In a future article I will talk more on compiling programs you are writing yourself using the GNU toolchain (using g++, ld, as etc), without relying on an IDE to do the compilation in the background.

Just updated your iPhone? You'll find new emoji, enhanced security, podcast transcripts, Apple Cash virtual numbers, and other useful features. There are even new additions hidden within Safari. Find out what's new and changed on your iPhone with the iOS 17.4 update.

Be the First to Comment

Share Your Thoughts