1.采用c++语言方式编译实现了静态库libTools.a,可供外部c程序调用的接口头文件interface_tools.h写法如下:
#ifndef _INTERFACE_TOOLS_H
#define _INTERFACE_TOOLS_H
#define HID_DLL_CALL
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
HID_DLL_CALL bool tCreateFileDir(char *str);
#ifdef __cplusplus
}
#endif
#endif
interface_tools.c文件写法如下,一定要注意包含interface_tools.h。
#include "interface_tools.h"
using namespace std;
bool tCreateFileDir(char *str)
{
bool ret = true;
return ret;
}
对比包含与不包含interface_tools.h头文件的区别:
包含该头文件的情况
$ nm lib/libTools.a
interface_tools.o:
0000000000000000 T tCreateFileDir
不包含该头文件的情况
$ nm lib/libTools.a
interface_tools.o:
0000000000000000 T _Z14tCreateFileDirPc
通过对比可以看出,不包含该头文件,生成的函数名带有前后缀。