Archived

This topic is now archived and is closed to further replies.

template

Python & C++

Recommended Posts

How exactly does one embed C++ in Python? Do I need to write my Python code in a .cpp or .h file and compile it into an EXE with a C++ compiler or do I write the C++ code in a Python .py file and the Python interpreter automatically compiles or interprets it? Also, does the C++ STL work with Python?

Share this post


Link to post
Share on other sites
quote:
Original post by Ruudje
ehm, python is a scripting language. C++ is a programming language. they''re not the same

Uh, dude - a "scripting" language is just as much a programming language as any other "non-scripting" programming language.

OP: Take a look at the Embedding and Extending[1] part in the Python documentation, or Boost:ython[2].

[1]http://www.python.org/doc/current/ext/ext.html
[2]http://www.boost.org/libs/python/doc/index.html

--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites
I believe SWIG (Simplified Wrapper Interface Generator) is what you seek. I use it at work to call C++ code from Perl, but it supports many more scripting languages. SWIG generates the interface from your header files automagically, and best of all, it''s free.

http://www.swig.org

--
Dave Mikesell
d.mikesell@computer.org
http://davemikesell.com

Share this post


Link to post
Share on other sites
Okay, few people say SWIG, some boost Python.
Here's the rundown -- Swig cons and pros
+ Swig goes over your declarations and produces C wrapper functions. So it doesn't really depend on your compiler.
+ boost Python doesn't yet support python 2.3
+ You must admit that boost's install process isn't as streamlined as it could be.
+ SWIG doesn't involve templates.
+ boost Python isn't really compatible with VC6, it barfs on some of the templates
- it generates both .c and .py files that are necessary for the system to work while boost is directly embedded in your C++ files. (i.e. you don't have to carry extraneous .py files, nor modify your build process)
- it's a separate tool. It doesn't fully support the language. You may have to add hints in your code or use a separate definition file.
- You have to be very very careful with the objects you pass around.


[edited by - deepdene on October 10, 2003 1:32:50 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Ruudje
ehm, python is a scripting language. C++ is a programming language. they''re not the same


You know, I''d be really interested in hearing the criteria you use to distinguish "scripting" and "programming" languages.


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites