extern C的使用

每个函数都有一个标识,C语言和C++对函数的标识是不同的。

今天在C++程序里面调用GeoIP(用C写的la静态库)里面的ip->as映射函数的时候,直接就可以调用,挺奇怪的,一看h文件里面有

 1 #ifndef GEOIP_H
2 #define GEOIP_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <sys/types.h>
9 #if !defined(_WIN32)
10
11 ……
12
13
14 GEOIP_API void GeoIP_setup_custom_directory(char *dir);
15 GEOIP_API GeoIP* GeoIP_open_type (int type, int flags);
16 GEOIP_API GeoIP* GeoIP_new(int flags);
17 GEOIP_API GeoIP* GeoIP_open(const char * filename, int flags);
18 GEOIP_API int GeoIP_db_avail(int type);
19
20 ……
21
22 #
23 #ifdef __cplusplus
24 }
25 #endif
26
27 #endif /* GEOIP_H */

也就不足为奇了。。。

原文地址:https://www.cnblogs.com/tzhangofseu/p/2245476.html