Linux software installation: Source code and software installation

Source: Internet
Author: User
Linux software installation: Source code and software installation 1 some basic concepts of open source software 1.1 What is open source code, compile programs and executable files executable file www.2cto. the files that can be executed in comLinux are binary files, such as/usr/bin/passwd,/bin/touchshel... linux software installation: some basic concepts of source code and software installation 1. what is open source code? 1.1, the files that can be really executed on Linux are binary files, such as/usr/bin/passwd,/bin/touchshell script only calls these binary files, to complete a function, run the file command to check the file type $ file/bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV ), dynamically linked (u Ses shared libs), for GNU/Linux 2.6.24, BuildID [sha1] = 0xf199a4a89ac968c2e0e99f2410600b9d7e995187, stripped $ file/etc/init. d/rc/etc/init. d/rc: POSIX shell script, where are the binary files that can be executed by the ASCII text executable compiler? First, you must write the program's source code, and then compile the program's source code into a binary form. The source code is compiled by programmers and uses specific programming languages, such as C, C ++, Java, and Python. however, the machine does not understand these languages, so it is necessary to compile the source code written in these languages into binary files that the machine can understand. For example, the common C language compiler is gcc. 1.2 What is a function library composed of a series of functions? each function is a code snippet to complete specific functions. in this way, when using some common functions, you do not have to rewrite the code yourself, you only need to call the functions in the function library. The function library is divided into static function libraries and dynamic function libraries. Www.2cto.com static function library extension :. a is directly compiled into a binary file. Therefore, the generated file is usually large. during the upgrade, you need to re-compile the dynamic function library extension :. so is not directly compiled into a binary file during compilation. it just provides a path pointing to the corresponding function library. The program dynamically reads data from this path during program execution. during the upgrade, you only need to replace the dynamic function library in the original path, you do not need to re-compile to use the ldd command to know which dynamic function library the program uses $ ldd/usr/bin/passwd linux-gate.so.1 => (0xb7784000) libpam. so.0 =>/lib/i386-linux-gnu/libpam. so.0 (0xb775c000) libpam_misc.so.0 =>/lib/i386-linux-gnu/libpam_misc.so.0 (0xb7758000) libselinux. so.1 =>/lib/i386-linux-g Nu/libselinux. so.1 (0xb7738000) libc. so.6 = & gt;/lib/i386-linux-gnu/libc. so.6 (0xb758e000) libdl. so.2 =>/lib/i386-linux-gnu/libdl. so.2 (0xb7589000)/lib/ld-linux.so.2 (0xb7785000) 1.3 what is make and configure when the number of files in the program is very large, it will become very troublesome to directly compile with gcc, then, we can write a file to define how to compile the entire program. This file is makefile, and then call the make command. the make command uses makefile to compile the program. How to generate makefile? generally, the software provider provides a configure program to detect the machine environment and generate makefile. The content to be checked includes whether there is a suitable compiler, whether there is a required function library, and whether the operating system version is suitable. 2 C language compilation Simple example use vim to write two program source code # include Int main (void) {thankYou (); printf ("hello, world \ n"); return 0 ;}# include Void thankYou () {printf ("Thank you \ n");} use gcc to compile this step. the source code file is compiled into the target file $ gcc-c hello. c-o hello. o $ gcc-c thank. c-o thank. o by using the gcc link, we can link the compiled target file in the function library with the target file we compiled and generated to form a final binary file $ gcc hello. o thank. o-o hi run $. /hiThank youhello, world Note: You can use-l to specify the function library,-L to specify the path of the function library, and-I to specify the path of the header file gcc sin. c-lm-L/lib-L/usr/lib-I/usr/include indicates that-l is added to the function library, and m indicates libm. so this function library 3 uses make for macro compilation of many www.2cto.com files, the compilation process is very cumbersome, and some files are updated. Yes, you need to re-compile, some have not been updated, and do not need to re-compile. some compilation processes need to be repeated many times. to automate the compilation process, you can compile makefile to describe how to compile, then, use make to automatically compile the entire process. Write makefile hi: hello. o thank. o gcc-o hi hello. o thank. o pay attention to Tab indentation before the second line. Make uses $ makecc-c-o hello. o hello. ccc-c-o thank. o thank. c run $. /hihello, worldThank you can see from the effect of make, we just need to write a shell script directly? Otherwise, you can see that in makefile, you only need to point out the target file required to generate hi, make can automatically find the corresponding source code file and compile it, and then use the link we provide for the link. In addition, if hello. c has been updated, make will judge again when making, only re-compile hello. c, which will save a lot of resources and time for large programs. In addition, variables can be defined in makefile to define how to delete the compiled target file OBJS = hello. o thank. o hi: hello. o thank. o gcc-o hi $ {OBJS} clean: rm hi $ {OBJS} test: $ ls hello. o thank. o hihello. o hi thank. o $ make cleanrm hi hello. o thank. o $ ls hello. o thank. o hils: cannot access hello. o: No such file or directoryls: cannot access thank. o: No such file or directoryls: cannot access hi: No such file or directory $ make cc-c-o hello. o hello. ccc-c-o thank. o thank. cgcc-o hi hello. o thank. o $ ls hello. o thank. o hihello. o hi thank. o $. /hihello, worldThank you4 install the software by compiling the source code, obtain the source code, decompress it, and enter the source code directory. /configure: execute configure and create makefile. This step is very important. The configure program will detect the operating system and library files required for compiling the source code. Before you execute it, you 'd better check the README or INSTALL files in the directory, see what you need to pay attention to. www.2cto.com make clean: execute some cleanup tasks according to the clean operation defined in makefile. make install: compile the files generated by makefile according to install defined in makefile. install to the appropriate directory

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.