Using g ++ to compile C Programs in Linux: XX does not define a solution

Source: Internet
Author: User
Use an example to illustrate how to use C header files/functions in C ++. For example, I have a C header file named C. the source code file of H and C is called C. c. The content is C. h: # ifndef _ asdfd_included _ # DEFINE _ asdfd_included _ # include <stdio. h> extern int test (int A); # endifc. c: # include "C. H "int test (int A) {printf (" A = % d \ n ", a); return a * A;} Now I want to use C. the function test () provided in C. The name of my c ++ file is. CPP, then the section related to C should be enclosed in the braces of extern "C" {} To see my. CPP: # include <iostream> using namespace STD; extern "C" {# include "C. H "} int main () {int B = 12; B = test (B); cout <"B =" <B <Endl; return 0;}. # include "C. H" is included by extern "C.
 
The following g ++ compilation will not result in the failure to find the function or structure in the header file.
Related Article

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.