cpp2c

28 篇文章 0 订阅
23 篇文章 0 订阅

What is cpp2c?

Cpp2C is an (extern) C wrapper code-generator for C++ code.

Cpp2C gets a C++ header file path and generate a thin C++ wrapper code with extern-C interface to that header file, allowing you to either statically link it to a C code or create a dynamic library with the proper extern-C interface and def file being auto-generated.

Why do I need it?

Possible uses:
  • Create an extern C interface to a C++ code, to be used as a dynamic library (including .def file generation).
  •  Reuse C++ code in a C program, either to improve performance or due-to partial support of the platform of C++ features (embedded\real-time operating systems come to mind).

 

Features

  • Transforms classes to opaque pointers, and (public) methods\operators\constructors\destructors to functions.
  •  Masks exceptions and returns them via output variable.
  • Inheritance and Polymorhism are implicitly supported by the C++ compiler.
  •  Handles function\operator overloading by creating a unique function name for each overloaded version.
  • Generates code for template instantiations (i.e. you cannot export the code of vector - but you can export the code of vector<int>), though the enforcement of the template instantiation (e.g. via explicit declaration in the header file:  template class std::vector<int>, etc.) is at the user's responsibility.
  • Supports reference variables as pointers.
  • Supports static methods.
  • Supports boolean variables for non-C99 supported compilers.

How to run cpp2c?

After downloading Cpp2C and all the required dependencies, stated here, you can simple run, for example:

cpp2c.py <c++_header_file_to_wrap_path>

under Linux, using gcc, or:

cpp2c.py <c++_header_file_to_wrap_path> -g <gcc_xml_path> -t msvc9

under Windows, using Visual Studio 2008.

 

You can view all the script parameters by typing:

cpp2c.py -h

Usage Examples

Examples for common cases:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值