1
Hello! I’m trying to compile my program into C++ (it calls a function written in the Perl language) and it’s returning a long list of errors "indefinite reference":
testeperl2principal.o: na função `S_croak_memory_wrap':
testeperl2principal.cpp:(.text+0xa): referência indefinida para `PL_memory_wrap'
testeperl2principal.cpp:(.text+0x14): referência indefinida para `Perl_croak_nocontext'
testeperl2principal.o: na função `main':
testeperl2principal.cpp:(.text+0x3d): referência indefinida para `perlWrapper::perlWrapper()'
testeperl2principal.cpp:(.text+0x4c): referência indefinida para `std::allocator<char>::allocator()'
testeperl2principal.cpp:(.text+0x64): referência indefinida para `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
testeperl2principal.cpp:(.text+0x73): referência indefinida para `std::allocator<char>::~allocator()'
(....)
Can anyone help me? I’m new with C++ and this whole compilation process... Thank you so much!
Codes:
//perlWrapper.h
#include "EXTERN.h"
#include "perl.h"
#include <iostream>
#include <string>
using namespace std;
class perlWrapper{
public:
perlWrapper();
~perlWrapper();
void runInterpreterWithPerlFile (char *file);
int getMathResult(int a, string perlFunc);
private:
PerlInterpreter *my_perl;
char *my_argv[2];
};
.cpp:
//perlWrapper.cpp
#include "perlWrapper.h"
using namespace std;
perlWrapper::perlWrapper(){
PERL_SYS_INIT3(NULL,NULL,NULL);
my_perl = perl_alloc();
perl_construct( my_perl );
PL_exit_flags = PERL_EXIT_DESTRUCT_END;
}
perlWrapper::~perlWrapper(){
perl_destruct(my_perl);
perl_free(my_perl);
PERL_SYS_TERM();
}
void perlWrapper::runInterpreterWithPerlFile(char *file){
string a = "";
char * S = new char[a.length()+1];
strcpy(S,a.c_str());
char *my_argv[] = {S, file};
perl_parse(my_perl,0,2,my_argv,(char**)NULL);
perl_run(my_perl);
}
int perlWrapper::getMathResult(int valor, string perlFunc){
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSViv(valor)));
PUTBACK;
call_pv(perlFunc.c_str(),G_SCALAR);
SPAGAIN;
int resultado = POPi;
PUTBACK;
FREETMPS;
LEAVE;
return resultado;
}
main:
#include <iostream>
#include <string>
#include "perlWrapper.h"
using namespace std;
int main(){
perlWrapper perlwrapper;
string a = "perlMath.pl";
char * S = new char[a.length()+1];
strcpy(S,a.c_str());
perlwrapper.runInterpreterWithPerlFile(S);
cout << perlwrapper.getMathResult(1, "multiplyByTwo");
cout<<endl;
return 0;
}
Makefile:
CPP=g++
CPPFLAGS=$(shell perl -MExtUtils::Embed -e ccopts)
LD=g++
LDFLAGS=$(shell perl -MExtUtils::Embed -e ldopts)
all: testeperl2principal
.cpp.o:
$(CPP) $(CPPFLAGS) -o $@ -c $<
perlteste2principal: perlWrapper.o testeperl2principal.o
$(LD) -o $@ $? $(LDFLAGS)
clean:
rm -f testeperl2principal *.o