in reply to Including existing C or CPP library using Inline

Undefined subroutine &main::do_SSW

You've provided some Inline::CPP config directives, but haven't really done anything to invoke Inline::CPP.
Hence the whole script gets parsed as a purely perl script ... and perl's parsing doesn't see any do_SSW sub.

Immediately following the use Inline CPP => .... line, insert the line:
use Inline CPP;
That will at least invoke Inline::CPP.
There may well be other problems - eg I expect that you will need to link to the cpp library (in the Config directives):
LIBS => '-L/your/lib/path -lyourlib',
Update: It would also be a good idea to stick:a
BUILD_NOISY => 1,
in the Config section.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Including existing C or CPP library using Inline
by bontus (Novice) on Mar 12, 2014 at 22:05 UTC

    Dear Rob,

    I followed your advise and including  use Inline CPP; did help. Now, I am still struggling with passing perl strings to the function itself, which I guess is the reason for the function not being found. I wrote another function that is supposed to just print the passed string via cout and I also get the subroutine not found error. Integers work fine though, so it seems that converting the perl strings to C++ strings needs some work around.

    Best, René
      I wrote another function that is supposed to just print the passed string via cout and I also get the subroutine not found error

      It's hard to be certain without seeing the code, but it sounds like Inline might be unable to bind to the function.
      Rather than having anything to do with the arguments being passed, this would more likely be due to an unrecognised type being returned by the function.

      We really need to see the code you've tried, along with the error messages you're getting in order to be of much assistance.

      Cheers,
      Rob
        Hi Rob,

        Here's the code I mentioned in my previous post. The 'add' function works properly if I execute it, whereas calling 'doSSW' results in a "Undefined subroutine" error. Thus my guess is that the issue lies with passing Perl strings to a C++ function.

        Best, René
        #!/usr/bin/perl use warnings; use Inline CPP => Config => BUILD_NOISY => 1, CLEAN_AFTER_BUILD => 0; use Inline CPP => Config => AUTO_INCLUDE => '#include "ssw_cpp.h"'; use Inline CPP; my $ref = "CAGCCTTTCTGACCCGGAAATCAAAATAGGCACAACAAA"; my $seq = "CTGAGCCGGTAAATC"; print add(3,5)."\n"; my $returned = cprintit($seq); print $returned."\n"; #my $cigar = do_SSW($seq,$ref); #print "$cigar\n"; __END__ __CPP__ using namespace std; string do_SSW(const char* queryC, const char* refC) { Inline_Stack_Vars; string query(queryC); string ref(refC); StripedSmithWaterman::Aligner aligner; StripedSmithWaterman::Filter filter; StripedSmithWaterman::Alignment alignment; aligner.Align(query.c_str(), ref.c_str(), ref.size(), filter, &ali +gnment); return alignment.cigar_string; } int add (const int a, const int b) { int c = a+b; return c; } int cprintit(const string seq) { cout << seq << endl; return 10; }