📖
📖
📖
📖
Job Memo
Search…
Cheat sheets of git and repo
Implement your own HIDL
Communicate with Kernel driver
Compile your own kernel and install
Notes of GDBus
introduction of Yocto project
Yocto – how to initialize your module?
Useful Linux Commands
Benefits of using Macro
Samba to create sharing folders between host and VM
How to write a daemon?
C/C++
Use dlopen and dlsym to get handler of dynamic library(.so)
argc? argv ?
How to use C api in C++ ?
What is void* ?
Utilize function pointers to build Handlers
Concepts of Makefile
Makefile parameters
Powered By
GitBook
How to use C api in C++ ?
C++ 可以引用其他 C語言寫的 api,這不意外。
但要怎麼做?
C++:
請在把要使用的 C api 的 header 用 extern “C” 包起來
1
extern "C"
2
{
3
#include "demo_c_api_A.h"
4
#include "demo_c_api_B.h"
5
}
Copied!
而要被使用的 C api 的 header:
demo_c_api_A.h:
1
#ifndef DEMO_C_API_A_H
2
#define DEMO_C_API_A_H
3
4
#include "aaa.h"
5
#include <bbb.h>
6
7
#ifdef __cplusplus
8
extern "C"
9
{
10
#endif
11
12
...
13
14
(C 的 header 原本該寫的東西)
15
16
...
17
18
#ifdef __cplusplus
19
}
20
#endif
21
22
#endif
Copied!
你也可以不要直接用 extern 標全部,單獨寫:
1
#ifndef DEMO_C_API_A_H
2
#define DEMO_C_API_A_H
3
4
#include "aaa.h"
5
#include <bbb.h>
6
7
extern int c_api_A_init();
8
9
10
(C 的 header 原本該寫的東西)
11
12
#endif
13
#endif
Copied!
延伸:extern 是什麼?
ref.
Why use #ifndef CLASS_H and #define CLASS_H in .h file but not in .cpp?
C/C++ - Previous
argc? argv ?
Next - C/C++
What is void* ?
Last modified
5mo ago
Copy link