in reply to Re^2: Inline CPP
in thread Inline CPP

Hi Rob, I managed to solve the linkage problem. I still have the problem with ENABLE => STD_IOSTREAM - I still need help in that aspect). Apparently in the test phase The LD_LIBRARY_PATH should have the path to the libmain.so (my external libraries). and it is not sufficient to have that path in the pm file (in the LIBS -L option in
use Inline (CPP => 'DATA', LIBS => '-L/users/nirf/perlTrials/cNewModule/lib -lmai +n -L/usr/lib -lstdc++', INC => '-I/users/nirf/perlTrials/inlineExample', WARNINGS => 0, NAME => 'PM_wed', VERSION => '0.01', BUILD_NOISY => 1, );
) Thanks, Nir

Replies are listed 'Best First'.
Re^4: Inline CPP
by nirf1 (Novice) on Jun 01, 2008 at 12:22 UTC
    Hi All, I am trying to call from perl script to a function that is defined inside another perl module. That module is an Inline::CPP, and the function I call to is a cpp function. The function gets a pointer to an int and needs to fill it:
    int add_nir(int x, int y, int* ref_int )
    I am trying to call that function with :
    my $test; add_nir(1,4,\$test);
    but I get the following error :
    Can't locate auto/PM_wed/add_nir.al in @INC (@INC contains: ...
    any other fuction (that doesn't receives a pointer) in the cpp part that is called from the perl script is propogated and executed correctly. Can someone please tell me what I did wrong? Thanks, Nir
      It may just be that \$test is not a reference to an int. In any case, I'd be rewriting add_nir(). I think the following does what you want:
      use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void add_nir(int x, int y, SV * ref_int) { sv_setiv(ref_int, x + y); } EOC my $test; add_nir(1, 4, $test); print $test, "\n"; # prints "5"
      I also seem to recall that there can be problems when one Inline function tries to access an Inline'd function in a module - but I'm not sure of the details. It's not all that difficult to remove the Inline dependency from a module (thereby making it the same as any other XS module). <plug>InlineX::C2XS and InlineX::CPP2XS can help with that </plug>.

      Cheers,
      Rob
        Hi Rob, Thanks for your help! I want to send a reference to array (test) from perl :
        my @test; my $reftest = \@test; add_nir(1,4,\$reftest);
        and fill that array inside a cpp funcion (add_nir(..)). I followed your previous reply and I am using the perl guts :
        int add_nir(int x, int y, AV** perlList ) { *perlList = newAV(); SV* perlItem=newSViv(2); av_push(*perlList, perlItem); ... }
        I am using second layer references (pointer to pointer) because first level reference (see the difference in <AV* perlList> at the function declarations ):
        int add_nir(int x, int y, AV* perlList )
        didn't work. (after I filled the array in add_nir and left the function to it's caller, the array was empty - does the function
        newAV()
        allocates on the stack or the heap?) As i said the first level reference compiled but the array was empty on returning to the perl :first redirection level
        my @test; add_nir(1,4,\@test); int add_nir(int x, int y, AV* perlList ) { perlList = newAV(); SV* perlItem=newSViv(2); av_push(perlList, perlItem); ...}
        and the second level redirection couldn't be used : when running a test using my module I got the following error:
        Can't locate auto/PM_wed/add_nir.al in @INC .....
        What should I do ? Thanks, Nir