My first excursion into XS I did not use h2xs. gbarr set up the base and I extended.
I followed the example and set it up WO using h2xs. I even got my Makefile.PL to compile. The problems being in the error messages presented by perl when I tried to execute the test. I started with
only one function, typemap, .pm and .xs built by hand.
I duplicate the exact test in C++ and it ran perfectly.
The function was an Init. You passed it nothing and recieved nothing. I just went into the c++ workd and initiaalized some static variables.
Nick Ing-Simmons wrote:
Billy N. Patton <[EMAIL PROTECTED]> writes:
Silvo,
This group chooses to help only other experts. Beginners are not welcome here. I've ask several questions about C++ and have recieved no response. Guess my questions were too trivial. Too obvious to an expert. Too far below them to answer.
That is not true. To far above us.
Perl isn't written in C++ it is written in C, so the perl core experts tend not to be C++ experts (e.g. I am probably one of strongest XS experts on this list, but an am only at best competent in C++ and templates and finer point of STL give me nightmares).
I, for one will be VERY impressed if you get h2xs to work in C++. THat was my original thought. Rather than writing the .xs and the .pm I'l just write a h2xs++ and be done with it. I quickly realized that this was an even larger task than the one I was trying to do with xs. SO back off and just put 1 function at a time and test it thoroughly as I go.
typmap ->ok
.xs -> compile ok
.pm -< ok
init.t -> crash and burn.
C++ is much more complex than C to wrap.
I have a scheme for day-job (which is currently encumbered and can't yet be released) which has over 2000 lines of perl to implement a tiny subset of C++ parsing sufficent to do "h2xs" equivalent for our day-job C++ library.
It has to understand:
name spaces
struct vs class
public vs protected
inheritance
overloaded functions
operators templates and instances thereof.
It can't wrap all those yet, but unless the "parser" can at least basically grasp the constructs it rapidly gets lost in the .h file.
A C++ class in a .h _has_ to mention all the private stuff and typically includes inline functions which have to be skipped over
etc.
And FWIW I never use h2xs for C code as it is much safer to write bindings by hand as XS code and even the relatively trivial task of parsing C declarations is often "wrong".
SilvioCVdeAlmeida wrote:
Hello,
How suitable is h2xs for generating C++Perl bindings? I couldn't manage it to work as I expected.
I'm trying to build a Perl module to access a C++ library, closely following "Extension based on .h and .c files" from h2xs manpage:
1. start dirs: h2xs -Afn Pack 2. copy .h and .c (.cc in my case) to Pack/ 3. create extension: h2xs -Oxan Pack head_1.h head2.h 4. archive and test: cd Pack perl Makefile.PL make dist make make test
It breaks in make test, because generated Pack.c (-- not Pack.cc as I wanted --) ask for C compilation, which do not find iostream, string, and other standard C++ headers.
Any help would be very appreciated.
Silvio
-- ___ _ ____ ___ __ __ / _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___ / _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \ /____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/ /___/ Texas Instruments ASIC Circuit Design Methodlogy Group Dallas, Texas, 214-480-4455, [EMAIL PROTECTED]