extern "C"
C++的模組或檔案中要使用到C所撰寫的函式時,若不加extern "C"時會遇到無法解析外部的symbol
請參考Name mangling的說明。
加上
extern "C"是告訴C++ Compiler不要對C的函式做Name mangling的動作。
一般會這樣使用:
code:

// header file 
#ifdef __cplusplus 
	extern "C" { // only need to export C interface if  used by C++ source code 
#endif 

function declaration;

#ifdef __cplusplus 
} 
#endif

所以更改Name manglingMyFun.h的程式:

#include<stdio.h>

#ifdef __cplusplus
	extern "C" {   
#endif

void MyFun();

#ifdef __cplusplus
}
#endif

參考:
1.Exporting C Functions for Use in C or C++ Language Executables
2.Using extern to Specify Linkage

回目錄
Written By James On 2004/04/30
Hosted by www.Geocities.ws

1