Getting Undefined Reference to Perl on C++ -
well, first of all, sorry bad english!
i'm new linux, g++ , perl, , i'm getting problems here.
i have code in g++ calls perl .pl file return information. right now, i'm returning 1 or 0 perl .pl file tests , understand how works. problem i'm getting $make:
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 string constant ‘char*’ [-wwrite-strings] main.cpp:112:41: warning: deprecated conversion string constant ‘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 `perl_push_scope' main.cpp:(.text+0x33): undefined reference `perl_save_int' main.cpp:(.text+0x73): undefined reference `perl_markstack_grow' main.cpp:(.text+0xcd): undefined reference `perl_stack_grow' main.cpp:(.text+0xfa): undefined reference `perl_newsvpv' main.cpp:(.text+0x10d): undefined reference `perl_sv_2mortal' main.cpp:(.text+0x13b): undefined reference `perl_call_pv' main.cpp:(.text+0x18f): undefined reference `perl_sv_2iv_flags' main.cpp:(.text+0x1bd): undefined reference `perl_free_tmps' main.cpp:(.text+0x1ca): undefined reference `perl_pop_scope' main.o: in function `main': main.cpp:(.text+0x206): undefined reference `perl_sys_init3' main.cpp:(.text+0x20b): undefined reference `perl_alloc' main.cpp:(.text+0x21d): undefined reference `perl_construct' main.cpp:(.text+0x265): undefined reference `perl_parse' main.cpp:(.text+0x272): undefined reference `perl_run' main.cpp:(.text+0x2fd): undefined reference `perl_destruct' main.cpp:(.text+0x30a): undefined reference `perl_free' main.cpp:(.text+0x30f): undefined reference `perl_sys_term' collect2: error: ld returned 1 exit status make: *** [main] error 1
the main.cpp code is:
#include <extern.h> #include <perl.h> #include <iostream> #include <cstdio> #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 (&argc, &argv, &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 << "resultado " << getinfoperl("email/email.txt") << endl; perl_destruct(my_perl); perl_free(my_perl); perl_sys_term(); foobar bla bla bla part code: doesn't matter. }
here makefile:
#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 $< all: emails emails: $(emails) main: $(mainobjs) $(ld) -l/usr/lib $(lflags) -o $@ $(mainobjs) clean: rm -f *.o
what did? i've tried installing libperl-dev package, update perl, , nothing solved. need fix this! can me?
update:
changed header main.cpp to:
#ifdef __cplusplus extern "c" { #endif #include "extern.h" #include "perl.h" #ifdef __cplusplus } #endif #include <iostream> #include <cstdio> #include "filedir.h"
didn't work...
the problem in makefile:
#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 $< all: emails emails: $(emails) main: $(mainobjs) $(ld) -l/usr/lib $(lflags) -o $@ $(mainobjs) clean: rm -f *.o
as can see, in line, code:
main: $(mainobjs) $(ld) -l/usr/lib $(lflags) -o $@ $(mainobjs)
should have $(lflags) after $(mainobjs), should be:
main: $(mainobjs) $(ld) -l/usr/lib -o $@ $(mainobjs) $(lflags)
now, linker working perfectly. i'm sorry, can't why necessary, i've discovered.
Comments
Post a Comment