In order to prevent unscrupulous site crawler crawling articles, hereby identified, reproduced please indicate the source of the article. Laplacedemon/shijiaqi.
Http://www.cnblogs.com/shijiaqi1066/p/6349243.html
There is a program, the code directory is as follows:
.
|--Calc
| |--calc.c
| '--calc.h
'--main.cpp
If main.cpp needs to call a function in Calc.h (CALC.C is C code)
After the traditional C programming requires # include "calc/calc.h", the function is declared and then called.
But since Main.cpp is a C + + code. The g++ compiler cannot compile by using the C-mode call.
Solution One:
If the amount of code in Calc is very small, or the code is written by itself can directly use C + + compatible with the characteristics of C, the CALC.C changed to Calc.cpp. can be compiled.
Solution Two:
At the top of each function in calc.h, add: extern "C"
The simpler scenario is:
extern " C " { void fun1 (int arg1); void fun2 (intint arg2); void fun3 (intint int arg3);}
If you are not sure whether the current compilation environment is C or C + +, you can:
extern " C " {#endifvoid fun1 (intvoid fun2 (intint) void fun3 (int int int arg3); #ifdef __cplusplus} #endif
Workaround Three:
What if someone else has written a header file that we can't modify? Rewrite a header file that is specifically used by C + +.
Example: Writing a header file cpp_calc.h
extern " C " "calc.h";}
In order to prevent unscrupulous site crawler crawling articles, hereby identified, reproduced please indicate the source of the article. Laplacedemon/shijiaqi.
Http://www.cnblogs.com/shijiaqi1066/p/6349243.html
C + + calls to function