Home >Backend Development >C++ >How to export c++ program
In C, symbols, including functions, variables and classes, are exported through the extern "C" keyword. Exported symbols are extracted and used according to C language rules between compilation units or when interacting with other languages.
C How to export a program
What is export?
Export is a process of extracting functions, variables or objects in a program from a compilation unit to other compilation units or libraries for use.
How to export in C
In C, symbols can be exported by using the extern
keyword.
Export function
<code class="cpp">// 导出函数 extern "C" int add(int a, int b);</code>
Export variable
<code class="cpp">// 导出变量 extern "C" int global_variable;</code>
Export class
<code class="cpp">// 导出类 extern "C" class MyClass { public: int member_variable; void member_function() {} };</code>
Reason for using extern "C"
extern "C"
keyword tells the compiler to export symbols according to the rules of C language. This is important for interacting with code written in other languages.
Other export options
In addition to using extern "C"
, there are other options for exporting symbols:
.h
): Contains the declaration of exported symbols and can be included in multiple compilation units. Export Notes
The above is the detailed content of How to export c++ program. For more information, please follow other related articles on the PHP Chinese website!