[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
ForProgramFor the designer, makefile is a hurdle we cannot go around. It may be difficult for users who are used to Visual C ++ to write makefiles. After all, the tool itself has helped us complete all the compilation procedures. But in Linux, everything has changed. No one will do it for you. EditingCodeIt depends on you, test depends on you, and the final automated compilation design depends on you. Think about it. If you download an open-source software but fail to automate the compilation, it will greatly damage your self-confidence in learning the code. So I understand this. We must learn to write makefile, at least the simplest makefile.
First, write the Add. c file,
[CPP] View plaincopy
-
- # Include "test. H"
-
- # Include <stdio. h>
-
- IntAdd (IntA,IntB)
-
- {
-
- ReturnA + B;
-
- }
-
-
- IntMain ()
-
- {
-
- Printf ("2 + 3 = % d \ n", Add (2, 3 ));
- Printf ("2-3 = % d \ n", Sub (2, 3 ));
-
- Return1;
-
- }
Write the sub. c file,
[CPP] View plaincopy
- # Include "test. H"
- IntSub (IntA,IntB)
- {
- ReturnA-B;
- }
Finally, write the test. h file,
[CPP] View plaincopy
- # Ifndef _ test_h
- # DEFINE _ test_h
- IntAdd (IntA,IntB );
- IntSub (IntA,IntB );
- # Endif
So how can we write makefile for these three simple files?
[CPP] View plaincopy
- test: Add. O sub. O
- gcc-O test Add. O sub. O
-
- Add. O: Add. C test. H
- gcc-C add. C
-
- sub. O: Sub. C test. H
- gcc-c sub. C
-
- clean:
- RM-RF test
- RM-RF *. O