python执行存在(&大)c ++代码 [英] python executing existent (&big) c++ code

查看:152
本文介绍了python执行存在(&大)c ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++程序,使用 cryptopp 库来解密/加密邮件。



两个接口方法 encrypt & 解密,接收字符串并通过 cryptopp 方法对其进行操作。


$ b b

有没有办法在Python中使用这两种方法,而不用手动包装所有 cryptopp &包含文件?



示例:



  import cppEncryptDecrypt 

string foo =testing
result = encrypt(foo)
printEncrypted string:,result

解决方案

如果你可以从C ++代码中创建一个DLL,暴露这两个方法(理想情况下为extern C,这使得所有接口任务更简单), ctypes 可以是答案,而不是需要任何第三方工具或扩展。否则,您可以选择 cython ,好老 SWIG SIP , a href =http://www.boost.org/doc/libs/1%5F40%5F0/libs/python/doc/index.html =nofollow> Boost ,... - - 许多,许多这样的第三方工具将让你的Python代码调用这两个C ++入口点,而不需要包装任何东西,但他们。


I have a program in C++ that uses the cryptopp library to decrypt/encrypt messages.

It offers two interface methods encrypt & decrypt that receive a string and operate on it through cryptopp methods.

Is there some way to use both methods in Python without manually wrapping all the cryptopp & files included?

Example:

import cppEncryptDecrypt

string foo="testing"
result = encrypt(foo)
print "Encrypted string:",result

解决方案

If you can make a DLL from that C++ code, exposing those two methods (ideally as "extern C", that makes all interfacing tasks so much simpler), ctypes can be the answer, not requiring any third party tool or extension. Otherwise, it's your choice between cython, good old SWIG, SIP, Boost, ... -- many, many such 3rd party tools will let your Python code call those two C++ entry points without any need for wrapping anything else but them.

这篇关于python执行存在(&大)c ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆