Learn Linux program with me (2) ------------------ Tools

zhaozj2021-02-08  258

I don't want to say to how to put and use which Linux begins to say, there is nothing to say to a programmer, there is always a Linux for you, huh,! I also hope to show you the process of learning Linux, and the head is given to the finger, the backward person does not take the detour. Linux / UNIX system works and Windows are completely different. Linux / UNIX emphasizes coordination cooperation between different programs, and Windows emphasizes simple easy-to-use powerful features, which caused both for programming tools. The use is very different. Windows generally uses integrated development environments, completes all work under a unified IDE, and Linux will achieve this through collaboration between a series of related tools, so it is not used to programming under Linux. Although there is also an integrated development environment under Linux, it is not necessarily running under all Linux, does not have versatility, and if you really want to learn Linux first using the most traditional tool definitely no two magic weapon. Let's learn about the four Dafa Treasures of Linux programming: GCC compiler, Make project file, (x) Emacs editor, GDB debugger. The GCC GCC is not more, huh, huh, first look at an example: #include using namespace std; int main () {cout << "hello world"; return 0;} The program doesn't have to say more , Use GCC compilation, GCC helloword.cpp -o helloword, -o denotes the file name to generate, hereby introduce some other useful parameters, if you want to join the debugging information Use -g, play a warning message -wall, optimize- O1-O2-O3, only compile into .o file without chain, automatic lookup file-dependent relationship with -mm (usually used to make Make). That's so, you can use it, Of course, it still has a lot of other parameters. When you use it, make make it is definitely a focus on Linux. It doesn't help you write any procedures, but help you manage the compilation and other operations (if you Need), basically is an engineering file that is equivalent to the integrated development environment under Windows, huh, huh. Many people say that its ability is much larger than the project file, but I didn't see it. It can be achieved if it can be implemented. It is only a good cabbage radish. Narcosis, if you want to program it under Linux, you have to learn it, and you know more about it, the greater it for your benefits. Many articles are talking about Make's various parameters, but there is no instance. I will start with an instance, I hope you can have a little harvest after you have seen it, the left side is the line number to go in actual, example:

1 # End File 2 Executable: = TEST3 # Compiler and Sign 4 CC = GCC5 CXX = G

6 cflags: = -g -wall7 cxxflags: = $ (cflags) 8 cxxflags = -md9 # library and path 10 libs: = - LSTLPORT_GCC_STLDEBUG11 LIBPATH: = - l / usr / local / lib12 includepath: = - i / usr / local / include / stlport / 13 objspath: = .. / OBJ / TEST / 14 ExecutablePath: = .. / Execute /

15 rm: = RM -F16 # Source 17 Source: = $ (Wildcard * .c) $ (Wildcard * .cpp) 18 OBJS: = $ (PatSubst% .c,%. O, $ (PatSubst% .cpp,% .o, $ (SOURCE))) 19 DEPS: = $ (PatSubst% .O,%. D, $ (OBJS)) 20 # rules 21.suffixes: .cpp .c .o .so .a .d22 $. Objspath)%. O:%. C23 $ (cc) $ (cxxflags) -c $ <-o $ @ 24 $ (objspath)%. O:%. CPP25 $ (CXX) $ (cxflags) -c $ O $ @ 26 $ (objspath)%. D:%. CPP27 $ (cxx) -mm $> $ @ 28 # main body section 29.phony: All DEPS OBJS CLEAN REBUILD30 All: $ (Executable) 31 $ (cxx) $ (CXXFLAGS) $ (LIBS) $ (Libpath) $ (AddPRefix $ (Objspath), $ (OBJS)) -O $ (Executable) 32 DEPS: $ (AddPRefix $ (Objspath), $ (DEPS) 33 Objs: $ (AddPRefix $ (Objspath), $ (OBJS)) 34 Clean: 35 @ $ (r) $ (objspath) *. O36 @ $ (r) $ (objspath) *. D37 @ $ (RM) $ (ExecutablePath) $ (Executable) 38 Rebuild: Clean All39 -InClude $ (AddPRefix $ (Objspath), $ (DEPS)) 40 $ (Executable): Objs

The above is all, huh, huh, let's start explanation, there is not to ask more advice: 1 Take a note in # ; 2 In Make, you can define a macro, similar to C Macro, in fact, it is replaced by the right side of the equal sign, there are two forms, one is: = Table is immediately replaced, the other is = indicating that it is not directly replaced, but is replaced when it is used. That is to say, if you change its value, the left value will change, and: = then take the first time; macro is in the form of $ (macro name) in use; 4,5 take Make Some of them are the macro names that are predefined, such as CC and CXX, CC will specify the compiler name when compiling C files, CXX specifies the compiler name when compiling C files, and will mention it; 6, 7, 8 Similarly for the internal macro, cflag is the parameter specified by compiling C files, cxxflag is the compiler parameter specified when compiling C files; 10-14 is the definition of several directories, will be used later, -l, -l, -I is the option to specify the path when the GCC is compiled; 15 Introduction Macro (I remember is), specify the command form used by deleting files; 17-19 This source, target, and dependent files are used, here, here What to say is that Make has many internal functions, in order to facilitate us to use, huh, usage is $ (function name parameter, parameter ...) The few functions used here: Wildcard All meets the back condition Value enumeration, PATSUBST is in the form of a file that meets the first parameter form in the third parameter into the second parameter, a bit winding, and a lot of functions, find a manual. 21. Suffixes is the keyword in Make, indicating the default rules of the file extension after not being used. In Make, there are some pre-defined default rules. For example, you have to compile C files, you don't need to specify Its rules, make you know how to deal with it, here, remove these rules is to use our own custom rules 22-27 Our custom rules are coming, huh, just, I spent a week. Understand, its grammar is very simple,% is a wildcard, that is, the * in the DIR command *, indicating that the previous one is generated by the rear, what is generated, through the following, 23 lines $ (cc) Indicates that C's compiler is the GCC we defined earlier, and then the back is a pile of parameter added value. Anyway, the final is the form of our ought. The whole meaning of this sentence is that when you encounter * .o files to process, find * .c files, pay attention to this * refers to the same file, how to use how to use the following bonus, of course you also You can write a similar statement to process compilation of other languages, this is the mix of make, haha. Also, $

There is also the one of 27> What do you mean? Document is the file generated when the compiler is automatically discovered by the compiler, and> Indicates that the result of its output is redirected to> back files, Not it may output to screen acres, this is not the result we want, as for why the .D file, will tell, huh, huh, a little giant, a keyword, indicating that all the back flags To enforce 30-38 body part, huh, we may often use this time when using Make, Make All, Make will find the ALL flag in the file. If there is, you will continue, the other is the same. Here, I have to talk about the basic problem in the Make file. Oh, now it is a bit late, it is a fixed rule matching method in the make file, it is: the previous representation of the target, the demonstration The files, while the one below means that the depends is processed, that is The program is so simple, and all everything is to achieve this purpose ..phony is to make mandatory processing, for the dependencies, it will find it from the next one, such as 38 lines Will first process the cleaning of Clean (find Clean's dependencies) and then processes the ALL, and it doesn't have itself. 39 include and C #include, including all GCC automatic generation dependencies (26-27 generation), This will not be used by our own, the front - means that when no file is found, the following work will continue, addPrefix represents the prefix representing the first parameter in front of each item of the second parameter. 40 Finally, we have to make a dependence on the final generated documents, complete it is tired, don't know if you understand, try, try it, and find a manual again, and the last thing to say is different. Make tool capabilities and parameters are different, see you again, rest

转载请注明原文地址:https://www.9cbs.com/read-2930.html

New Post(0)