qingsongzdq 2020-02-02
#include <iostream>
using namespace std;
extern "C" void func() {
}
extern "C" void func(int v) {
}
int main() {
getchar();
return 0;
}可能是用C语言写的开源库
int sum(int v1, int v2){
return v1 + v2;
}
int delta(int v1, int v2) {
return v1 - v2;
}
#include <iostream>
using namespace std;
extern "C" {
#include "math.h"
}
int main() {
cout << sum(10, 20) << endl;
cout << delta(10, 20) << endl;
getchar();
return 0;
}#include <iostream>
using namespace std;
#include "math.h"
int main() {
cout << sum(10, 20) << endl;
cout << delta(10, 20) << endl;
getchar();
return 0;
}这需要宏定义 编译器在C++环境里面预先定义了一个宏,只要是C++文件就有一个隐形的宏存在 #define __cplusplus 定义在最前面,隐形的代码,如下所示 #define __cplusplus //c++文件默认加的,看不见,不需要额外写 #include <iostream> using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
int sum(int v1, int v2);
int delta(int v1, int v2);
#ifdef __cplusplus
}
#endif#ifndef ABC //判断宏ABC有没有定义 #define ABC #endif
#ifndef math.h
#define math.h
#ifdef __cplusplus
extern "C" {
#endif
int sum(int v1, int v2);
int delta(int v1, int v2);
#ifdef __cplusplus
}
#endif
#endif