Zi 字媒體
2017-07-25T20:27:27+00:00
LINUX C/C++ C++中是如何使用C開發的API(o/a/so/dll)
資料來源: https://mp.weixin.qq.com/s/NNJyZtQaLkbGSbhLkDZZIg
test.c
#include"test.h"
void testCfun()
{
printf("I am c fun\n");
return;
}
test.h
#include
extern "C"{
void testCfun();
}
main.cpp
#include"test.h"
#include
using namespace std;
int main(void)
{
/*调用C接口*/
cout<
編譯:
$ gcc -c test.c
$ g++ -o main main.cpp test.o
$ ./main
start to call c function
I am c fun
end to call c function
——-
test.h
#include
#ifdef __cplusplus
extern "C"{
#endif
void testCfun();
#ifdef __cplusplus
}
#endif
main.c
#include"test.h"
int main(void)
{
/*调用C接口*/
testCfun();
return 0;
}
寫了
5860316篇文章,獲得
23313次喜歡