How to Write C/C ++ mixed-encoding makefile

Source: Internet
Author: User

I thought it was very simple to use the mixed programming of C and C ++, but I didn't expect it to take a little time. Here is a summary.

1. For the C part, use gcc-c-o XXX. o xxx. C.

For the C ++ part, use g ++-c-o XXX. o xxx. cpp.

C ++ part. If you want to use C, use

Extern "C "{}

2. For example, I have several files, A. cpp A. h B. H C. C. H D. C D. H.

The inclusion relationship here is:. CPP contains main,. h uses B. class in H, B. c. h, where B. c ++ code in H

C. H uses the functions declared in D. H.

Makefile is written as follows:

A:. o C. o d. OG ++-o. o C. o d. oa. o:. cpp. h B. h c. OG ++-c-o. o. cppc. o: C. c. h d. ogcc-c-o C. o C. CD. o: D. c d. hgcc-c-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.