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
#includeextern "C"{ void testCfun(); }
main.cpp
#include"test.h" #includeusing 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; }