Hi Rob, from the cpp and header I created a shared object. Than I called that shared oblect from test.pl file. The test.pl file checks that the shared object is ok (and it worked). Than I wanted to have the same thing inside a pm file (and it just does't go for me). And this is the reason for my current problems. As i sad, wjen calling that shared object from a simple pl file everything works fine. The output of the pl file is -------------------outout of test.pl----------------
I'm constructing : Global array I'm constructing : in add I am inside wow Destruction : in add 9 + 16 = 25 Destruction : Global array
-----------------main.h-----------------------
#ifndef _nir_test_main #define _nir_test_main #include <string> using namespace std; class MyClass { public: MyClass(const char*); ~MyClass(); int wow(); private : string _my_favorite_argument; }; #endif
-----------------main.cpp-----------------------
#include <stdio.h> #include "main.h" //extern int funcOuter(int); MyClass::MyClass(const char * a_my_favorite_argument) { printf("I'm constructing : %s \n",a_my_favorite_argument); _my_favorite_argument.append(a_my_favorite_argument); } MyClass::~MyClass() { printf("Destruction : %s \n",_my_favorite_argument.c_str()); } int MyClass::wow() { printf ("I am inside wow \n"); return 12 / 3; } int func(const int&); int main (int argc, char* argv[]) { //calling to a function from another so //funcOuter(4); printf ("hello \n"); int x = 10; func(x); return 0; } int func (const int& x) { printf ("in func : %d \n",x); return 0; }
------------------test.pl----------------------------
#!/usr/bin/perl -w use lib '/usr/lib/perl5/vendor_perl/5.8.0'; use lib '/users/nirf/perlTrials/cpanModulesInstallation/lib/perl5/site +_perl/5.8.0'; use lib '/users/nirf/perlTrials/cpanModulesInstallationInline/lib/perl +5/site_perl/5.8.5'; #use lib '/users/nirf/perlTrials/cpanModulesInstallationParseRecDescen +t/lib/perl5/site_perl/5.8.5'; #use Inline Config => LIBS => '-L/users/nirf/perlTrials/inlineExample' +, LIBS => '-lmain'; #use Inline Config => LIBS => '-L/users/nirf/perlTrials/inlineExample +-lmain'; use Inline CPP => Config => INC => '-l/users/nirf/perlTrials/inlineExa +mple'; use Inline CPP => Config => MYEXTLIB => '/users/nirf/perlTrials/inline +Example/libmain.so'; + use Inline CPP; + sub func { add(1,1); } print "9 + 16 = ", add(9, 16), "\n"; + __END__ __CPP__ + #include "main.h" char GlobalArr[13] = {'G','l','o','b','a','l',' ','a','r','r','a',' +y','\0',}; MyClass myGlobalInstance(GlobalArr) ; int add(int x, int y) { char arr[7]={'i','n',' ','a','d','d','\0'}; MyClass mc(arr); myGlobalInstance.wow(); return x + y; }
Thanks, Nir

In reply to Re^7: inline in a perl module by nirf1
in thread inline in a perl module by nirf1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.