C函數和C++函數相互調用
test.c
int call_MyMath_sum (int,int);
int sum(inta , intb) {
return call_MyMath_sum(a,b);
}
main.cpp
#include <iostream>
using namespace std;
extern"C" {
int sum(int, int);
}
class MyMath {
public:
static int sum(int, int);
};
intMyMath::sum(inta, intb) {
return(a + b);
}
extern"C" int call_MyMath_sum (inta , intb) {
return(MyMath::sum(a,b));
}
int main(void) {
cout<<sum(5,6);
return0;
}
Makefile
main.o:
g++ -c -o main.o main.cpp
test.o:
gcc -c -o test.o test.c
main: main.o test.o
g++ -o main main.o test.o
all: clean main
clean:
rm -f test.o main.o