extern "C" :
2010-11-05 21:16
106 查看
1)范围:C++的语法,C中编译会报错
2) 作用:
a)告诉编译器这是一个全局的
b)告诉编译器产生类C的符号(int foo(int) c:_foo c++:_foo_int)
3) 常见写法:
extern "C" int foo(int a);
extern "C" int bar();
extern "C"
{
int foo();
int bar();
}
4)常见地点:
a)c++中调用C的lib,需要用extern "C"来修饰用到的c的头文件。
b)用c++写用来给c/c++使用的lib,也可以用extern "C"来修饰。
如果你想让你的程序使用范围更广,那就加上extern "C"吧!
PS:Test code
test.cpp
extern "C"
{
__declspec(dllexport) int foo(int a){ return 0;}
__declspec(dllexport) int bar(int a,int b){ return 0;}
}
cl /TP /LD test.cpp
使用dependency.exe可以查看生成的test.dll内部函数名
2) 作用:
a)告诉编译器这是一个全局的
b)告诉编译器产生类C的符号(int foo(int) c:_foo c++:_foo_int)
3) 常见写法:
extern "C" int foo(int a);
extern "C" int bar();
extern "C"
{
int foo();
int bar();
}
4)常见地点:
a)c++中调用C的lib,需要用extern "C"来修饰用到的c的头文件。
b)用c++写用来给c/c++使用的lib,也可以用extern "C"来修饰。
如果你想让你的程序使用范围更广,那就加上extern "C"吧!
PS:Test code
test.cpp
extern "C"
{
__declspec(dllexport) int foo(int a){ return 0;}
__declspec(dllexport) int bar(int a,int b){ return 0;}
}
cl /TP /LD test.cpp
使用dependency.exe可以查看生成的test.dll内部函数名
相关文章推荐
- extern "C"的用法解析
- extern “C"的作用
- extern "c"
- 深入理解C/C++混合编程(关于#ifdef __cplusplus extern "C" {...}的用法)
- “#ifdef __cplusplus extern "C" { #endif”的定义-----C和C++的互相调用
- C++项目中的extern "C" {}
- static extern 以及 extern "c"
- 在DLL编程中,导出函数为什么需要extern "C"
- extern "C" 的作用
- extern "C"
- 探索C++的秘密之详解extern "C"
- extern "c"解释
- extern "C"什么意思
- extern "C"详解
- C++项目中的extern "C" {}
- C++中 extern "C" 的两种用法
- define AB_EXTERN extern "C" __attribute__((visibility ("default")))
- extern "C" __stdcall对函数的使用声明
- extern "C"的用法解析
- 探索C++的秘密之一详解extern "C"