没有合适的资源?快使用搜索试试~ 我知道了~
首页SWIG:C/C++程序多语言接口工具
SWIG:C/C++程序多语言接口工具
需积分: 13 2 下载量 32 浏览量
更新于2024-07-25
收藏 1.51MB PDF 举报
"SWIG 是一个软件开发工具,用于简化将C和C++程序与不同语言接口的任务。它主要是一个编译器,能够处理C/C++声明,并为包括Perl、Python、Tcl、Ruby、Guile和Java在内的多种语言生成所需的包装器。SWIG通常不需要修改现有代码,且能在短时间内构建出可用的接口。"
在SWIG的2.0文档中,包含了多个部分,旨在帮助用户理解和使用这个强大的工具:
1. **Preface**:这一章节提供了关于SWIG的基本介绍,包括不同版本的信息、SWIG的许可证、可用资源、先决条件、手册的组织结构、如何避免阅读手册(可能是指通过实践快速上手)、向后兼容性、发布注记、贡献者名单、错误报告以及安装指南。
- **安装**:在安装部分,SWIG提供了针对不同操作系统的具体步骤,如Windows、Unix和Macintosh OS X的安装过程,并有测试和示例的说明。
2. **Introduction**:这一部分深入解释了SWIG是什么,为什么需要使用SWIG,以及如何使用SWIG。通过一个简单的例子展示了SWIG接口文件的创建、SWIG命令的使用,以及如何为Perl5和Python构建模块。此外,还提到了SWIG支持的C/C++语言特性,非侵入式的接口构建方法,以及如何将SWIG整合到构建系统中。
3. **Getting started on Windows**:这部分专为Windows用户设计,详细介绍了在Windows平台上的安装过程,包括可执行文件的获取和安装步骤。
文档的其余部分可能包含SWIG的核心文档、特定语言模块的文档和开发者文档,这些内容将详细介绍SWIG的工作原理、各种语言模块的使用方法以及为开发者提供的高级功能和扩展选项。
SWIG是一个强大的工具,它使得C和C++程序可以方便地与其他编程语言交互,极大地扩展了代码的可访问性和复用性。通过学习和应用SWIG,开发者可以快速地构建跨语言的软件系统,而无需对原始代码进行大量修改。
Table of Contents
29 SWIG and Ocaml
29.2.4.4 Sample Session.......................................................................................................................................464
29.2.5 Director Classes................................................................................................................................................464
29.2.5.1 Director Introduction..............................................................................................................................464
29.2.5.2 Overriding Methods in Ocaml................................................................................................................464
29.2.5.3 Director Usage Example........................................................................................................................464
29.2.5.4 Creating director objects........................................................................................................................465
29.2.5.5 Typemaps for directors, directorin, directorout, directorargout.............................................................466
29.2.5.6 directorin typemap..................................................................................................................................466
29.2.5.7 directorout typemap................................................................................................................................466
29.2.5.8 directorargout typemap..........................................................................................................................466
29.2.6 Exceptions........................................................................................................................................................466
30 SWIG and Octave......................................................................................................................................................................467
30.1 Preliminaries...............................................................................................................................................................467
30.2 Running SWIG...........................................................................................................................................................467
30.2.1 Command-line options.....................................................................................................................................468
30.2.2 Compiling a dynamic module..........................................................................................................................468
30.2.3 Using your module...........................................................................................................................................468
30.3 A tour of basic C/C++ wrapping................................................................................................................................468
30.3.1 Modules............................................................................................................................................................469
30.3.2 Functions..........................................................................................................................................................469
30.3.3 Global variables................................................................................................................................................469
30.3.4 Constants and enums........................................................................................................................................470
30.3.5 Pointers.............................................................................................................................................................470
30.3.6 Structures and C++ classes...............................................................................................................................471
30.3.7 C++ inheritance................................................................................................................................................473
30.3.8 C++ overloaded functions................................................................................................................................473
30.3.9 C++ operators...................................................................................................................................................473
30.3.10 Class extension with %extend........................................................................................................................474
30.3.11 C++ templates.................................................................................................................................................475
30.3.12 C++ Smart Pointers........................................................................................................................................476
30.3.13 Directors (calling Octave from C++ code).....................................................................................................476
30.3.14 Threads...........................................................................................................................................................477
30.3.15 Memory management.....................................................................................................................................477
30.3.16 STL support....................................................................................................................................................478
30.3.17 Matrix typemaps.............................................................................................................................................478
31 SWIG and Perl5.........................................................................................................................................................................479
31.1 Overview.....................................................................................................................................................................480
31.2 Preliminaries...............................................................................................................................................................480
31.2.1 Getting the right header files............................................................................................................................480
31.2.2 Compiling a dynamic module..........................................................................................................................480
31.2.3 Building a dynamic module with MakeMaker.................................................................................................481
31.2.4 Building a static version of Perl.......................................................................................................................481
31.2.5 Using the module..............................................................................................................................................482
31.2.6 Compilation problems and compiling with C++..............................................................................................483
31.2.7 Compiling for 64-bit platforms........................................................................................................................484
31.3 Building Perl Extensions under Windows..................................................................................................................485
31.3.1 Running SWIG from Developer Studio...........................................................................................................485
31.3.2 Using other compilers.......................................................................................................................................485
31.4 The low-level interface...............................................................................................................................................485
31.4.1 Functions..........................................................................................................................................................486
31.4.2 Global variables................................................................................................................................................486
SWIG-2.0 Documentation
xv
Table of Contents
31 SWIG and Perl5
31.4.3 Constants..........................................................................................................................................................486
31.4.4 Pointers.............................................................................................................................................................487
31.4.5 Structures..........................................................................................................................................................488
31.4.6 C++ classes.......................................................................................................................................................489
31.4.7 C++ classes and type-checking........................................................................................................................490
31.4.8 C++ overloaded functions................................................................................................................................490
31.4.9 Operators..........................................................................................................................................................491
31.4.10 Modules and packages....................................................................................................................................491
31.5 Input and output parameters.......................................................................................................................................492
31.6 Exception handling.....................................................................................................................................................494
31.7 Remapping datatypes with typemaps.........................................................................................................................495
31.7.1 A simple typemap example..............................................................................................................................496
31.7.2 Perl5 typemaps.................................................................................................................................................497
31.7.3 Typemap variables............................................................................................................................................497
31.7.4 Useful functions................................................................................................................................................498
31.8 Typemap Examples....................................................................................................................................................499
31.8.1 Converting a Perl5 array to a char **...............................................................................................................499
31.8.2 Return values....................................................................................................................................................500
31.8.3 Returning values from arguments....................................................................................................................500
31.8.4 Accessing array structure members..................................................................................................................501
31.8.5 Turning Perl references into C pointers............................................................................................................502
31.8.6 Pointer handling................................................................................................................................................502
31.9 Proxy classes...............................................................................................................................................................503
31.9.1 Preliminaries.....................................................................................................................................................503
31.9.2 Structure and class wrappers............................................................................................................................503
31.9.3 Object Ownership.............................................................................................................................................505
31.9.4 Nested Objects..................................................................................................................................................506
31.9.5 Proxy Functions................................................................................................................................................506
31.9.6 Inheritance........................................................................................................................................................507
31.9.7 Modifying the proxy methods..........................................................................................................................507
31.10 Adding additional Perl code.....................................................................................................................................508
32 SWIG and PHP..........................................................................................................................................................................509
32.1 Generating PHP Extensions........................................................................................................................................509
32.1.1 Building a loadable extension..........................................................................................................................510
32.1.2 Using PHP Extensions......................................................................................................................................510
32.2 Basic PHP interface....................................................................................................................................................510
32.2.1 Constants..........................................................................................................................................................510
32.2.2 Global Variables...............................................................................................................................................511
32.2.3 Functions..........................................................................................................................................................512
32.2.4 Overloading......................................................................................................................................................512
32.2.5 Pointers and References...................................................................................................................................512
32.2.6 Structures and C++ classes...............................................................................................................................513
32.2.6.1 Using -noproxy.......................................................................................................................................514
32.2.6.2 Constructors and Destructors.................................................................................................................514
32.2.6.3 Static Member Variables........................................................................................................................515
32.2.6.4 Static Member Functions.......................................................................................................................515
32.2.7 PHP Pragmas, Startup and Shutdown code......................................................................................................515
32.3 Cross language polymorphism...................................................................................................................................516
32.3.1 Enabling directors.............................................................................................................................................517
32.3.2 Director classes.................................................................................................................................................517
32.3.3 Ownership and object destruction....................................................................................................................518
32.3.4 Exception unrolling..........................................................................................................................................519
SWIG-2.0 Documentation
xvi
Table of Contents
32 SWIG and PHP
32.3.5 Overhead and code bloat..................................................................................................................................519
32.3.6 Typemaps.........................................................................................................................................................520
32.3.7 Miscellaneous...................................................................................................................................................520
33 SWIG and Pike...........................................................................................................................................................................521
33.1 Preliminaries...............................................................................................................................................................521
33.1.1 Running SWIG.................................................................................................................................................521
33.1.2 Getting the right header files............................................................................................................................521
33.1.3 Using your module...........................................................................................................................................522
33.2 Basic C/C++ Mapping................................................................................................................................................522
33.2.1 Modules............................................................................................................................................................522
33.2.2 Functions..........................................................................................................................................................522
33.2.3 Global variables................................................................................................................................................522
33.2.4 Constants and enumerated types......................................................................................................................523
33.2.5 Constructors and Destructors...........................................................................................................................523
33.2.6 Static Members.................................................................................................................................................523
34 SWIG and Python......................................................................................................................................................................524
34.1 Overview.....................................................................................................................................................................525
34.2 Preliminaries...............................................................................................................................................................525
34.2.1 Running SWIG.................................................................................................................................................525
34.2.2 Using distutils...................................................................................................................................................526
34.2.3 Hand compiling a dynamic module..................................................................................................................527
34.2.4 Static linking.....................................................................................................................................................528
34.2.5 Using your module...........................................................................................................................................529
34.2.6 Compilation of C++ extensions........................................................................................................................530
34.2.7 Compiling for 64-bit platforms........................................................................................................................531
34.2.8 Building Python Extensions under Windows...................................................................................................531
34.3 A tour of basic C/C++ wrapping................................................................................................................................532
34.3.1 Modules............................................................................................................................................................532
34.3.2 Functions..........................................................................................................................................................533
34.3.3 Global variables................................................................................................................................................533
34.3.4 Constants and enums........................................................................................................................................534
34.3.5 Pointers.............................................................................................................................................................534
34.3.6 Structures..........................................................................................................................................................536
34.3.7 C++ classes.......................................................................................................................................................537
34.3.8 C++ inheritance................................................................................................................................................538
34.3.9 Pointers, references, values, and arrays............................................................................................................539
34.3.10 C++ overloaded functions..............................................................................................................................539
34.3.11 C++ operators.................................................................................................................................................540
34.3.12 C++ namespaces.............................................................................................................................................541
34.3.13 C++ templates.................................................................................................................................................542
34.3.14 C++ Smart Pointers........................................................................................................................................543
34.3.15 C++ reference counted objects.......................................................................................................................543
34.4 Further details on the Python class interface..............................................................................................................543
34.4.1 Proxy classes....................................................................................................................................................544
34.4.2 Built-in Types...................................................................................................................................................545
34.4.2.1 Limitations.............................................................................................................................................545
34.4.2.2 Operator overloads -- use them!.............................................................................................................547
34.4.3 Memory management.......................................................................................................................................548
34.4.4 Python 2.2 and classic classes..........................................................................................................................550
34.5 Cross language polymorphism...................................................................................................................................550
34.5.1 Enabling directors.............................................................................................................................................551
SWIG-2.0 Documentation
xvii
Table of Contents
34 SWIG and Python
34.5.2 Director classes.................................................................................................................................................551
34.5.3 Ownership and object destruction....................................................................................................................552
34.5.4 Exception unrolling..........................................................................................................................................553
34.5.5 Overhead and code bloat..................................................................................................................................553
34.5.6 Typemaps.........................................................................................................................................................554
34.5.7 Miscellaneous...................................................................................................................................................554
34.6 Common customization features................................................................................................................................554
34.6.1 C/C++ helper functions....................................................................................................................................554
34.6.2 Adding additional Python code........................................................................................................................555
34.6.3 Class extension with %extend..........................................................................................................................557
34.6.4 Exception handling with %exception...............................................................................................................558
34.7 Tips and techniques....................................................................................................................................................559
34.7.1 Input and output parameters.............................................................................................................................560
34.7.2 Simple pointers.................................................................................................................................................561
34.7.3 Unbounded C Arrays........................................................................................................................................562
34.7.4 String handling.................................................................................................................................................563
34.8 Typemaps....................................................................................................................................................................563
34.8.1 What is a typemap?..........................................................................................................................................563
34.8.2 Python typemaps..............................................................................................................................................565
34.8.3 Typemap variables............................................................................................................................................565
34.8.4 Useful Python Functions..................................................................................................................................566
34.9 Typemap Examples....................................................................................................................................................567
34.9.1 Converting Python list to a char **..................................................................................................................567
34.9.2 Expanding a Python object into multiple arguments........................................................................................568
34.9.3 Using typemaps to return arguments................................................................................................................569
34.9.4 Mapping Python tuples into small arrays.........................................................................................................570
34.9.5 Mapping sequences to C arrays........................................................................................................................570
34.9.6 Pointer handling................................................................................................................................................571
34.10 Docstring Features....................................................................................................................................................572
34.10.1 Module docstring............................................................................................................................................572
34.10.2 %feature("autodoc").......................................................................................................................................573
34.10.2.1 %feature("autodoc", "0")......................................................................................................................573
34.10.2.2 %feature("autodoc", "1")......................................................................................................................573
34.10.2.3 %feature("autodoc", "2")......................................................................................................................573
34.10.2.4 %feature("autodoc", "3")......................................................................................................................574
34.10.2.5 %feature("autodoc", "docstring").........................................................................................................574
34.10.3 %feature("docstring").....................................................................................................................................574
34.11 Python Packages.......................................................................................................................................................575
34.12 Python 3 Support......................................................................................................................................................575
34.12.1 Function annotation........................................................................................................................................575
34.12.2 Buffer interface...............................................................................................................................................575
34.12.3 Abstract base classes......................................................................................................................................577
35 SWIG and R...............................................................................................................................................................................578
35.1 Bugs............................................................................................................................................................................578
35.2 Using R and SWIG.....................................................................................................................................................578
35.3 Precompiling large R files..........................................................................................................................................579
35.4 General policy.............................................................................................................................................................579
35.5 Language conventions................................................................................................................................................579
35.6 C++ classes.................................................................................................................................................................579
35.7 Enumerations..............................................................................................................................................................579
SWIG-2.0 Documentation
xviii
Table of Contents
36 SWIG and Ruby.........................................................................................................................................................................580
36.1 Preliminaries...............................................................................................................................................................581
36.1.1 Running SWIG.................................................................................................................................................582
36.1.2 Getting the right header files............................................................................................................................582
36.1.3 Compiling a dynamic module..........................................................................................................................582
36.1.4 Using your module...........................................................................................................................................583
36.1.5 Static linking.....................................................................................................................................................583
36.1.6 Compilation of C++ extensions........................................................................................................................583
36.2 Building Ruby Extensions under Windows 95/NT....................................................................................................584
36.2.1 Running SWIG from Developer Studio...........................................................................................................584
36.3 The Ruby-to-C/C++ Mapping....................................................................................................................................585
36.3.1 Modules............................................................................................................................................................585
36.3.2 Functions..........................................................................................................................................................585
36.3.3 Variable Linking...............................................................................................................................................586
36.3.4 Constants..........................................................................................................................................................586
36.3.5 Pointers.............................................................................................................................................................587
36.3.6 Structures..........................................................................................................................................................587
36.3.7 C++ classes.......................................................................................................................................................588
36.3.8 C++ Inheritance................................................................................................................................................589
36.3.9 C++ Overloaded Functions..............................................................................................................................591
36.3.10 C++ Operators................................................................................................................................................592
36.3.11 C++ namespaces.............................................................................................................................................592
36.3.12 C++ templates.................................................................................................................................................593
36.3.13 C++ Standard Template Library (STL)..........................................................................................................593
36.3.14 C++ STL Functors..........................................................................................................................................595
36.3.15 C++ STL Iterators..........................................................................................................................................595
36.3.16 C++ Smart Pointers........................................................................................................................................596
36.3.17 Cross-Language Polymorphism.....................................................................................................................597
36.3.17.1 Exception Unrolling.............................................................................................................................597
36.4 Naming.......................................................................................................................................................................597
36.4.1 Defining Aliases...............................................................................................................................................598
36.4.2 Predicate Methods............................................................................................................................................599
36.4.3 Bang Methods...................................................................................................................................................599
36.4.4 Getters and Setters............................................................................................................................................600
36.5 Input and output parameters.......................................................................................................................................600
36.6 Exception handling.....................................................................................................................................................602
36.6.1 Using the %exception directive........................................................................................................................602
36.6.2 Handling Ruby Blocks.....................................................................................................................................603
36.6.3 Raising exceptions............................................................................................................................................604
36.6.4 Exception classes..............................................................................................................................................605
36.7 Typemaps....................................................................................................................................................................605
36.7.1 What is a typemap?..........................................................................................................................................605
36.7.2 Typemap scope.................................................................................................................................................607
36.7.3 Copying a typemap...........................................................................................................................................608
36.7.4 Deleting a typemap...........................................................................................................................................608
36.7.5 Placement of typemaps.....................................................................................................................................608
36.7.6 Ruby typemaps.................................................................................................................................................609
36.7.6.1 "in" typemap..........................................................................................................................................609
36.7.6.2 "typecheck" typemap..............................................................................................................................610
36.7.6.3 "out" typemap........................................................................................................................................610
36.7.6.4 "arginit" typemap...................................................................................................................................610
36.7.6.5 "default" typemap...................................................................................................................................611
36.7.6.6 "check" typemap.....................................................................................................................................611
36.7.6.7 "argout" typemap....................................................................................................................................611
SWIG-2.0 Documentation
xix
剩余733页未读,继续阅读
点击了解资源详情
点击了解资源详情
点击了解资源详情
2016-12-08 上传
2021-04-29 上传
2021-06-08 上传
2021-06-13 上传
2021-05-17 上传
2021-05-18 上传
jacky19710511
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Raspberry Pi OpenCL驱动程序安装与QEMU仿真指南
- Apache RocketMQ Go客户端:全面支持与消息处理功能
- WStage平台:无线传感器网络阶段数据交互技术
- 基于Java SpringBoot和微信小程序的ssm智能仓储系统开发
- CorrectMe项目:自动更正与建议API的开发与应用
- IdeaBiz请求处理程序JAVA:自动化API调用与令牌管理
- 墨西哥面包店研讨会:介绍关键业绩指标(KPI)与评估标准
- 2014年Android音乐播放器源码学习分享
- CleverRecyclerView扩展库:滑动效果与特性增强
- 利用Python和SURF特征识别斑点猫图像
- Wurpr开源PHP MySQL包装器:安全易用且高效
- Scratch少儿编程:Kanon妹系闹钟音效素材包
- 食品分享社交应用的开发教程与功能介绍
- Cookies by lfj.io: 浏览数据智能管理与同步工具
- 掌握SSH框架与SpringMVC Hibernate集成教程
- C语言实现FFT算法及互相关性能优化指南
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功