How to compile a program in LInux

Author: Florence Bailey
Date Of Creation: 20 March 2021
Update Date: 1 July 2024
Anonim
How to Compile and Run C program Using GCC on Ubuntu 18.04 LTS (Linux) / Ubuntu 20.04 LTS
Video: How to Compile and Run C program Using GCC on Ubuntu 18.04 LTS (Linux) / Ubuntu 20.04 LTS

Content

Source code is a computer program in human readable form. But the computer cannot run the source code - to do this, it needs to be compiled into a program.

Steps

  1. 1 Download the source code (program or driver) from the Internet. Most likely, you will download an archive with the extension .tar, .tar.bz2, .tar.gz. or .zip (rare).
  2. 2 Unpack the archive. For .zip, use the unzip filename command; for .tgz or .tar.gz use tar -zxvf filename; for .bz2 use tar -jxvf filename; or use a graphical interface.
  3. 3 In a terminal, change to the unpacked directory (cd dirName).
  4. 4 Run the command./ configure to automatically configure the source code. Use the --prefix = argument to specify the installation directory. The command will check for the required libraries.
  5. 5 Once configured, run the make command, which will compile the program (this can take from a few seconds to several hours). The executable file of the program will be placed in the bin directory (in the directory with the source code).
  6. 6 To install the program, run the make install command.
  7. 7 You have compiled and installed the program.

Tips

  • If the compilation fails, delete the files created during the previous compilation (to avoid errors when recompiling). Then compile again.
  • If you have a multi-core computer, you can compile the program in a multithreaded process with make -j3 (replace 3 with the number of threads you want to use).
  • If the compilation fails, additional information is displayed. You can try to fix the problem. Most of the problems are related to the dependencies of the downloaded source code (lack of the necessary programs or libraries).
  • If you did not specify a directory for installation, the program will be installed in / usr.
  • You need to be the superuser.
  • You can enter commands on one line, for example ./configure && make && make install.

Warnings

  • Compiling and replacing important system components can create problems.
  • Compilation can take several hours.
  • Some source packages do not contain configuration files or even compilation files. In this case, type make in a terminal and see the output.