Swarm FAQ:Writing C plusplus
(Redirected from Swarm FAQ:writing cplusplus)
Q. How do I interface Swarm with my own C++ code?
A. C++ used to be relatively difficult to interface into Swarm, because C++'s runtime object system is incompatible with the Objective C object system. But see the Objective-C++ item below.
One advantage of using C++ is that it could execute faster than Objective-C (for reasons discussed at: Swarm_FAQ:Speedups#Objective-C_Swarm).
Some choices are:
- Providing C language bindings for all methods and instance variable accessor routines for your C++ objects, which can then be called from your Swarm Objective C code. This is very time consuming, and brittle to model updates.
- Use DCOM bindings in Swarm (this link is broken: http://www.santafe.edu/~mgd/banff/banff.htm )
- Use Classdesc http://ecolab.sf.net/classdesc.html. See Richard Leow and Russell K. Standish, "Running C++ Models under the Swarm Environment", Proceedings SwarmFest '03. http://www.nd.edu/~swarm03/Program/Abstracts/LoewSwarm2003.pdf. Note that whilst the Objective-C bindings created by Richard Leow are still distributed as part of Classdesc, it is not supported by the EcoLab project, and some work would be needed to get this working with modern compilers. Anyone doing this is welcome to contribute their code back into the EcoLab project.
- Use Objective-C++. In the cvs repository there is now a Swarm library for Objective-C modified to be compatible with Objective-C++. You need gcc compiler version 4.1.2 or newer. Compile with the statement: make OBJC='gcc -x objective-c++'
Classdesc pretty much automates the first approach. The DCOM relies on a language independent OO interface. The DCOM bindings in Swarm are not well documented unfortunately. There is also a suspicion that DCOM adds a lot of extra runtime overheads, avoided by the other techniques.
![[Main Page]](/stylesheets/images/wiki.png)