← 返回命令列表

Linux command

swig 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Generate Python wrapper

swig -python [interface.i]

Generate with C++

swig -c++ -python [interface.i]

Specify output file

swig -python -o [wrap.c] [interface.i]

Include directory

swig -I[/usr/include] -python [interface.i]

Generate Java wrapper

swig -java [interface.i]

说明

swig (Simplified Wrapper and Interface Generator) generates wrapper code that allows C and C++ libraries to be called from other programming languages. It reads interface definition files (.i) that describe which functions, classes, and types to expose, and produces the glue code needed for the target language. Supported target languages include Python, Java, Ruby, Perl, PHP, Lua, Go, JavaScript, C#, and many others. SWIG handles automatic type conversion and data marshaling between C/C++ and the target language, including complex types, pointers, arrays, and object-oriented constructs like inheritance and templates. Interface files use a syntax similar to C/C++ header files with additional SWIG directives for controlling the wrapping process. SWIG can also parse actual C/C++ header files directly for simpler cases.

参数

-python
Python target.
-java
Java target.
-ruby
Ruby target.
-c++
C++ mode.
-o _FILE_
Output file.
-I _DIR_
Include path.
-module _NAME_
Module name.

FAQ

What is the swig command used for?

swig (Simplified Wrapper and Interface Generator) generates wrapper code that allows C and C++ libraries to be called from other programming languages. It reads interface definition files (.i) that describe which functions, classes, and types to expose, and produces the glue code needed for the target language. Supported target languages include Python, Java, Ruby, Perl, PHP, Lua, Go, JavaScript, C#, and many others. SWIG handles automatic type conversion and data marshaling between C/C++ and the target language, including complex types, pointers, arrays, and object-oriented constructs like inheritance and templates. Interface files use a syntax similar to C/C++ header files with additional SWIG directives for controlling the wrapping process. SWIG can also parse actual C/C++ header files directly for simpler cases.

How do I run a basic swig example?

Run `swig -python [interface.i]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -python do in swig?

Python target.