title: Getting Undefined Reference to Perl on C++
body: <p>Well, first of all, sorry about my bad english!</p>
  
  <p>I'm new to linux, g++ and perl, and I'm getting some problems here.</p>
  
  <p>I have a code in G++ which calls a perl .pl file to return a information. Right now, I'm just returning 1 or 0 from the perl .pl file for tests and to understand how does it works. But the problem is that I'm getting this from the $make:</p>
  
  <pre><code>sathlervbn Spam C # make clean;make
  rm -f *.o
  g++  -Wall  -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/lib/perl/5.14/CORE   -c -o filedir.o filedir.cpp
  g++  -Wall  -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fstack-protector -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  -I/usr/lib/perl/5.14/CORE   -c -o main.o main.cpp
  main.cpp: In function ‘int main(int, char**, char**)’:
  main.cpp:112:41: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  main.cpp:112:41: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
  g++ -L/usr/lib -Wall -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.14/CORE -    lperl -ldl -lm -lpthread -lc -lcrypt -o main filedir.o main.o
  main.o: In function `getInfoPerl(std::string)':
  main.cpp:(.text+0x1a): undefined reference to `Perl_push_scope'
  main.cpp:(.text+0x33): undefined reference to `Perl_save_int'
  main.cpp:(.text+0x73): undefined reference to `Perl_markstack_grow'
  main.cpp:(.text+0xcd): undefined reference to `Perl_stack_grow'
  main.cpp:(.text+0xfa): undefined reference to `Perl_newSVpv'
  main.cpp:(.text+0x10d): undefined reference to `Perl_sv_2mortal'
  main.cpp:(.text+0x13b): undefined reference to `Perl_call_pv'
  main.cpp:(.text+0x18f): undefined reference to `Perl_sv_2iv_flags'
  main.cpp:(.text+0x1bd): undefined reference to `Perl_free_tmps'
  main.cpp:(.text+0x1ca): undefined reference to `Perl_pop_scope'
  main.o: In function `main':
  main.cpp:(.text+0x206): undefined reference to `Perl_sys_init3'
  main.cpp:(.text+0x20b): undefined reference to `perl_alloc'
  main.cpp:(.text+0x21d): undefined reference to `perl_construct'
  main.cpp:(.text+0x265): undefined reference to `perl_parse'
  main.cpp:(.text+0x272): undefined reference to `perl_run'
  main.cpp:(.text+0x2fd): undefined reference to `perl_destruct'
  main.cpp:(.text+0x30a): undefined reference to `perl_free'
  main.cpp:(.text+0x30f): undefined reference to `Perl_sys_term'
  collect2: error: ld returned 1 exit status
  make: *** [main] Error 1
  </code></pre>
  
  <p>The main.cpp code is:</p>
  
  <pre><code>#include &lt;EXTERN.h&gt;
  #include &lt;perl.h&gt;
  #include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include "filedir.h"
  
  using namespace std;  
  
  PerlInterpreter *my_perl;
  
  int getInfoPerl(string email){
      dSP;
      ENTER;
      SAVETMPS;
      PUSHMARK(SP);
      XPUSHs(sv_2mortal(newSVpv(email.c_str(),0)));
      PUTBACK;
      call_pv("spamTeste", G_SCALAR);
      SPAGAIN;
  
      int resultado = POPi;
      PUTBACK;
      FREETMPS;
      LEAVE;
  
      return resultado;
  
  }
  
      int main(int argc, char **argv, char **env) {
  
      char *my_argv[] = { " ", "spamPerl.pl" };
      PERL_SYS_INIT3 (&amp;argc, &amp;argv, &amp;env);
  
      my_perl = perl_alloc();
      perl_construct ( my_perl );
      PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
  
      perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL);
      perl_run(my_perl);
  
      cout &lt;&lt; "Resultado " &lt;&lt; getInfoPerl("email/email.txt") &lt;&lt; endl;
  
      perl_destruct(my_perl);
      perl_free(my_perl);
  
      PERL_SYS_TERM();
  
      foobar bla bla bla another part from the code: doesn't matter.
  }
  </code></pre>
  
  <p>Here is the makefile:</p>
  
  <pre><code>#CC= /usr/bin/g++
  CPP = g++
  CPPFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ccopts)
  #LD= /usr/bin/g++
  LD = g++
  
  LFLAGS = -Wall $(shell perl -MExtUtils::Embed -e ldopts)
  
  #LFLAGS = -Wall -Wl,-E  -fstack-protector -L/usr/local/lib  -L/usr/lib/perl/5.14/CORE -lperl     -ldl -lm -lpthread -lc -lcrypt
  
  MAINOBJS = filedir.o main.o
  
  EMAILS = main
  
  EXECS = $(EMAILS)
  
  #Regra Implicita:
  .c.o:
      $(CPP) $(CPPFLAGS) -c $&lt;
  
  all: emails
  
  emails: $(EMAILS)
  
  main: $(MAINOBJS)
      $(LD) -L/usr/lib $(LFLAGS) -o $@ $(MAINOBJS)
  
  clean:
      rm -f *.o
  </code></pre>
  
  <p>What I did? I've tried installing libperl-dev package, update the perl, and nothing solved. 
  I really need to fix this! Can someone help me?</p>
  
  <p>UPDATE:</p>
  
  <p>Changed the Header from main.cpp to:</p>
  
  <pre><code>#ifdef __cplusplus
  extern "C" {
  #endif
  #include "EXTERN.h"
  #include "perl.h"
  #ifdef __cplusplus
  }
  #endif
  
  #include &lt;iostream&gt;
  #include &lt;cstdio&gt;
  #include "filedir.h"
  </code></pre>
  
  <p>Didn't work...</p>