How to compile programs in Linux

Source: Internet
Author: User
Article title: describes how to compile programs in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Everyone will download the source code of the program sooner or later, and then try to compile it. If you are a loyal follower of RedHat or Debian, you will eventually find that a program is neither too old nor too new, and you are looking for compiled binary code. The bad one is that the code may never be correctly compiled whatever you do. most Linux programs are only beta versions at most. The good one is that the number of programs with no problems in compilation has increased over the past five years, and even if you are not a programmer, you can "fix" those that cannot compile the code correctly.

After downloading, there should be a certain type of compressed package on your hard disk. First, you must extract it (uncompress) and untar it to a directory. In practice, many people put them in this directory:/usr/src. In this way, all things can be put in one place, and you can clear them later. To use this directory, you must have the root identity. If a file packaged with tar is compressed with gzip, the Linux tar program can decompress it and decompress the package at the same time. If your file name is filename.tar.gz, you can go to the/usr/src directory and type:

Tar-xzvf/{path to file}/export filename.tar.gz} [Enter]

This will decompress the file and unpack it. Here is a simple explanation of several parameters: x-unpack the file z-decompress the file v-display the processing process f-followed by the package file name to be processed. if you use netscape to download the file, you may see an error. Sometimes netscape will decompress the file for you.

Therefore, if you untar it like above, you may see the following information:

Gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error exit delayed from previous errors

Try to execute the preceding command, but delete the z parameter, as shown in the following code: tar-xvf/{path to file}/{filename.tar.gz} [Enter]. The z parameter does not work for such files. The easiest way to unlock this file is the bunzip2 the-program.tar.bz2. In this example, the the-program.tar file is unwrapped by the following command:

Tar-xvf/{path to file}/export filename.tar.gz} [Enter]

After unpacking: cd will be included in the directory created just after unpacking. Use ls to check the files in this directory. First, read the README and INSTALL files. If you have not read these files, do not get help from others. This is why RTFM is widely used online (RTFM is short for 'read The Fucking manual. The README and INSTALL files will show you how to compile and INSTALL this program.

Compile it and run the "make" command. To enable "make" to start compilation, you must have a file named Makefile (you can also write the make parameter on the command line, but it is not within the scope of this article) there are usually three methods to start compilation: simple, Imake, and configure.

Simple compilation: If you see a file named Makefile -- no file named Imake or configure, you can use this method to compile it. Because it cannot be set for your computer, there are many problems with this method. The README and INSTALL files usually tell you how to edit some files so that they can be compiled normally. Generally, you can do this:

Make [Enter] make install [Enter]

If everything works, you can run the program now.

Imake: If the ls directory shows the Imake file and there is no Makefile, you can use this method. This is an old method for compiling. Basically, you need to enter:

Xmkmf [Enter] make [Enter] make install [Enter] Configure:

If the directory contains a file named configure, use this method. This is the easiest way to compile a program, and the compilation success rate is very high. Essentially, it will check your system to view every possible crying and supporting file to ensure that you can compile this program and then create Makefile based on the correct information. Run the following command:

./Configure [Enter] make [Enter] make install [Enter]

[1] [2] Next page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.