Re: Inline CPP Question/Issue
[email protected] ("Sisyphus")
| Newsgroups | perl.inline |
|---|---|
| Message-ID | <3D5170E033F748208219AB17F0F5F4C1@desktop2> |
----- Original Message ----- From: "David Oswald" <[email protected]> To: "McIntyre, Shane K." <[email protected]>; "inline" <[email protected]> Sent: Friday, July 13, 2012 4:16 AM Subject: Re: Inline CPP Question/Issue > On Thu, Jul 12, 2012 at 11:03 AM, McIntyre, Shane K. > <[email protected]> wrote: >> I am writing a Perl module (.pm file) that has C++ code in it. When I >> attempt to start up apache and the Perl modules get compiled the C++ >> method >> in the file does not get bound to Perl. That generally means that everything has compiled ok - it's just that there's a problem in the perl bindings. >> I am not having the same issue with >> other Perl Modules where I use Inline C only ones where I have Inline >> CPP. >> I am using Perl version 5.8.8. Is there something different that needs >> to >> be done for C++ vs. C? Not really, but are you using current versions of Inline::C and Inline::CPP ? >> Right now I have a very basic Perl Module that I’m >> just trying to get to work. The code is below. Any help/guidance you >> could >> give me would be appreciated. >> >> >> >> use strict; >> >> >> >> use Inline CPP => (‘Config’ => >> >> DIRECTORY => >> ‘/projects/langid/apache/_Inline’, >> >> ); >> >> >> >> use Inline CPP => <<’END_CPP’; >> >> >> >> double factorial (int x) { >> >> int i; >> >> double result = 1; >> >> for (i=2; i<=x; i++) result *=I; >> >> return result; >> >> } >> >> END_CPP >> >> 1; There's a typo in the code - '*=I' should be '*=i'. But that shouldn't cause the error you're getting. I *think* 5.8.8 should know how to return a double but just in case it doesn't, try this version of the function: SV * factorial (int x) { int i; double result = 1; for (i=2; i<=x; i++) result *=i; return newSVnv(result); } If that works, but reverting to 'double' fails, then it's just that your perl typemap doesn't provide the necessary information on how to return a double. In that case, the typemap could be fixed - but it's probably easier (and certainly no less efficient) to use the function as I have written it. Or update to a later version of perl. Cheers, Rob