C++和C语言代码相互调用

一、C++调用C函数实例(关键是让C++调用的C接口按照C规范走即可)

注:可以先将C语言函数编译成静态库

// --------------cfun.h
#ifndef __C_FUN_H__
#define __C_FUN_H__
 
#ifdef __cplusplus
extern "C"{
#endif // __cplusplus
 
    void cfun();
#ifdef __cplusplus
}
#endif
#endif

二、C调用C++函数实例(关键是让C调用的C++函数接口按照C规范走即可)

// --------------cppfun.h
#ifndef _CPP_FUN_H__
#define _CPP_FUN_H__
extern "C" void cppfun();
#endif

猜你喜欢

转载自blog.csdn.net/qq_33657251/article/details/83691748
今日推荐