C Language Development in Linux (prepared by makefile) 02

Source: Internet
Author: User

[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
  1. # Include "test. H"
  2. # Include <stdio. h>
  3. IntAdd (IntA,IntB)
  4. {
  5. ReturnA + B;
  6. }
  7. IntMain ()
  8. {
  9. Printf ("2 + 3 = % d \ n", Add (2, 3 ));
  10. Printf ("2-3 = % d \ n", Sub (2, 3 ));
  11. Return1;
  12. }

Write the sub. c file,

[CPP] View plaincopy
    1. # Include "test. H"
    2. IntSub (IntA,IntB)
    3. {
    4. ReturnA-B;
    5. }

Finally, write the test. h file,

[CPP] View plaincopy
    1. # Ifndef _ test_h
    2. # DEFINE _ test_h
    3. IntAdd (IntA,IntB );
    4. IntSub (IntA,IntB );
    5. # Endif

So how can we write makefile for these three simple files?

[CPP] View plaincopy
    1. test: Add. O sub. O
    2. gcc-O test Add. O sub. O
    3. Add. O: Add. C test. H
    4. gcc-C add. C
    5. sub. O: Sub. C test. H
    6. gcc-c sub. C
    7. clean:
    8. RM-RF test
    9. RM-RF *. O

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.