- 首先,我们先需要添加一个外壳,外壳的功能是:将c++的类的方法进行包装,形成类似C语言的库函数
我们需要建立一个.cpp文件和一个头文件,例如:
HBShell.cpp:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "HrvBike.h"
#include "HBShell.h"
hrvBikeInterface *pInterface = NULL;
//int isOk = 0;
void initHrvInterface() {
if (pInterface == NULL) {
pInterface = new hrvBikeInterface();
}
}
//hrvBike.calHrvParamsMain(spath, despath, age, gender);
void calHrvParamsMain(char* spath, char* despath,

在Linux环境下,为了使C代码能够调用C++编写的动态库,需要创建一个C语言兼容的外壳。创建HBShell.cpp和HBShell.h,将C++类方法包装成C函数。使用g++编译生成动态库libHrv.so,并在C源文件test.c中包含HBShell.h。使用g++编译test.c并链接动态库,确保避免c与c++库的混淆问题,最终生成可执行文件test。

842

被折叠的 条评论
为什么被折叠?



