2014年10月6日 星期一

[C] How to make C call c++





/* b.h */
#ifndef _B_H_
#define _B_H_

#ifdef __cplusplus
extern "C" {
#endif
int add(int a, int b);
#ifdef __cplusplus
}
#endif
#endif

/* b.cpp */
#include "b.h" <-- must include "b.h"

int add(int a, int b) {
return a + b;
}



/* a.c */
#include <stdio.h>
#include "b.h" <-- must include "b.h"

int main(void) {
printf
("%d\n", add(3, 5));
return 0;
}

Reference:

1. 從 C 呼叫 C++ 函式的過程理解程式編譯、連結的原理

Related Posts:

0 意見:

張貼留言