Hi Michael,
> I am a software engineer for Suss Microtec. I have searched for a
> way to glue our existing c++ libraries with a simple perl Tk front end
> and inline seems like an excellent choice.
Cool. I happen to agree.
> I am running Linux with
> 2.2.16 and I can make my perl script work if I actually place the
> class headers and member function definitions in the perl script.
> But, I need to have my Perl script in one file, my c++ .h in another
> file and my member function definitions in another (.cc). Is there a
> way to do this?
I tried an example that's quite similar sounding. The "full version" is
downloadable at http://ttul.org/~nwatkiss/Inline/cppexample.tar.gz -- I'll
describe a shortened example here:
Set up a directory like this:
liba.pl
mystuff.h
mystuff.cpp
Here's what's in the files:
----8<---- (liba.pl)
use Cwd qw(cwd);
use Inline (CPP => cwd . '/mystuff.h',
LIBS => '-L' . cwd . ' -lmystuff');
my $p = new Airplane(100); # 100 passenger airplane
print "Plane is current en-route to ", $p->destination(), "\n";
$p->takeoff;
print "Plane is now en-route to ", $p->destination(), "\n";
$p->land("Denver");
print "Plane has now landed in ", $p->destination(), "\n";
---->8----
----8<---- (mystuff.h)
#ifndef __MYSTUFF_H__
#define __MYSTUFF_H__
class Airplane {
public:
Airplane(int passengers);
~Airplane();
int takeoff();
int land(char *where);
char *destination() { return m_dest; }
bool am_flying();
private:
char *m_dest;
int m_passengers;
bool m_flying;
};
#endif
---->8----
----8<---- (mystuff.cpp)
#include "mystuff.h"
Airplane::Airplane(int passengers) {
m_passengers = passengers;
m_dest = "Nowhere";
m_flying = false;
}
Airplane::~Airplane() { }
int Airplane::takeoff() {
m_dest = "The middle of nowhere";
m_flying = false;
}
int Airplane::land(char *where) {
m_dest = where;
m_flying = false;
}
bool Airplane::am_flying() {
return m_flying;
}
---->8----
Here's how to get it all running:
1. Build the library: (obviously unnecessary for existing libs)
$ g++ -c mystuff.cpp -o mystuff.o
$ ar cr libmystuff.a mystuff.o
2. Check that Inline binds properly
$ perl -MInline=info liba.pl
3. Run it again (just to see how much faster it is! :)
I'd try grabbing the tarball and trying it. Please let me know if you have
troubles.
Thanks,
Neil