Resolves errors such as unresolved external symbol "int __cdecl addInC1 (void)" ("addinc1@ @YAHXZ)" When C + + calls to function __jquery

Source: Internet
Author: User

Directly in the CPP write #include "c.h" reference to the C header file will be connected when this error occurs: Cpp.obj:error lnk2001:unresolved external symbol "int __cdecl Add (int,int) "([email=?add@ @YAHHH @z]?add@ @YAHHH @z[/email]), the root cause is that C + + and C differ in the way that functions are named.

C to the function name: _add

C + + On the name of the function: =?add@ @YAHHH @z

Solution: Do not modify the original C header file on the basis of the CPP file inside the extern "C" {#include "c.h"}, extern "C" {} means to interpret the code in C, so that c.h inside the code and functions are interpreted as C form. or modify the original C header file:

#ifdef __cplusplus
extern "C"
{
#endif

/*all of your code in here*/

#ifdef __cplusplus
}
#endif

Example:

C1.h:

#ifndef C1_h
#define C1_h

int addInC1 ();
#endif

C2.h

#ifndef C2_h
#define C2_h
#ifdef __cplusplus
extern "C"
{
#endif
int addInC2 ();

#ifdef __cplusplus
}
#endif
#endif

Cpp.cpp:

#include "C1.h"
#include "C2.h"

int main ()
{
int t1=addinc1 ();
int T2=addinc2 ();

};

Error

1 >cpp.obj:error lnk2019:unresolved external symbol _ADDINC2 referenced in function _main
2>cpp.obj:error lnk2019:unresolved external symbol "int __cdecl addInC1 (void)" (? addinc1@ @YAHXZ) referenced in funct Ion _main

Error 1 Cannot find C function _addinc2, error 2 is unable to find C + + function (? addinc1@ @YAHXZ).

Resolve Error 2:

Modify #include "C1.h"

To

extern "C"
{
#include "C1.h"
}

Resolve Error 1: Add a c2.c file to implement the addInC2. Add a c1.c file to achieve addInC1.

Reference: http://www.cnblogs.com/kenkofox/archive/2009/11/05/1597053.html

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.