codesoar has asked for the wisdom of the Perl Monks concerning the following question:
i have .h and .cpp file:
say_hi.h:
extern "C" { void say_hi(); }
say_hi.cpp:
#include <cstdio> #include "say_hi.h" void say_hi(){ printf("hello workd!\n"); }
then i compile this with
g++ -I. -fPIC -c *.cpp g++ -shared *.o -I. -olibsay_hi.so
then use perl Inline CPP to call it:
>perl -e 'use Inline CPP=>q{ \ #include "say_hi.h" \ void test(){return say_hi(); } \ }, INC=>"-I.",LIBS=>"-lsay_hi"; test()'
Here I got:
perl: symbol lookup error: /home/xxx/test_so/_Inline/lib/auto/e_8555/e_8555.so: undefined symbol: say_hi
But if I test the .so file with below .cpp file test.cpp:
#include "say_hi.h" main() { say_hi(); }
Compile it:
g++ -L. -lsay_hi test.cpp -o test
Run the test:
>test hello workd!
Is there something wrong with my Perl (v5.8.0), or did I miss anything?
thanks a lot!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: use Inline CPP to call function in so file not working
by syphilis (Archbishop) on Jan 09, 2014 at 06:04 UTC | |
by Anonymous Monk on Jan 09, 2014 at 07:49 UTC | |
by codesoar (Novice) on Jan 10, 2014 at 06:34 UTC | |
Re: use Inline CPP to call function in so file not working
by davido (Cardinal) on Jan 09, 2014 at 04:18 UTC | |
by codesoar (Novice) on Jan 10, 2014 at 06:59 UTC | |
by syphilis (Archbishop) on Jan 10, 2014 at 09:03 UTC | |
by Anonymous Monk on Jan 10, 2014 at 08:24 UTC | |
Re: use Inline CPP to call function in so file not working
by Anonymous Monk on Jan 09, 2014 at 04:03 UTC |
Back to
Seekers of Perl Wisdom