How to call the function of C reservoir from Perl

zhaozj2021-02-08  218

How to call the function of C reservoir from Perl

If the library you use is MYLIB.A header file is MYLIB.H, if MYLIB.H is like the following: EXTERN VOID HELLO (); hello () function If you do: Void Hello () {Printf ("Success Call from Perl TO C Libray! / n ";

First, establish a working directory mytest, put myLib.a and mylib.h in Mytest, execute h2xs -o-n mytest ./mytest/mylib.h three, enter Mytest.xs, modify mytest.xs. Add Perl interface void Hello () code: hello (); change #include <./ mytest / mylib.h> To be amended to the #include "mylib.h". Fourth, modify makefile.pl, where #add begin and #add end are new. use ExtUtils :: MakeMaker;. # See lib / ExtUtils / MakeMaker.pm for details of how to influence # the contents of the Makefile that is written WriteMakefile ( 'NAME' => 'mytest', 'VERSION_FROM' => 'mytest. PM ', # finds $ version' libs '=> [' '], # Eg,' -lm '' define '=>', # Eg, '-dhave_something' 'incrhave =>', # EG, '-I / usr / include / other' #add begin 'myextlib' => 'mylib.a', #add end); #add begin sub my :: postamble () {'$ (myextlib):.'; # Add end} 5, execute Perl makefile.pl, let Perl generate Makefile 6. Implement Make Seven, modify test file Test.pl, change to executive #! / usr / bin / perl # before `make install 'IS Performed this script should be runnable with # `make test '. After` make INSTALL' IT SHOULD WORK AS `Perl Test.pl '

#####################################################################################################################################################################################

# Change 1..1 Below to 1..last_test_to_print. # (It May Become Useful if The test is moved to ./t subdirectory.)

Use extutils :: testlib; begin {$ | = 1; print "1/9";} end {print "not ok 1 / n" unless $ loaded;} us mytest; $ loading = 1; print "OK 1 / n "; ################## End of black MAGIC.

# Insert your test code below (better if it prints "ok 13" # (Correspondingly "Not Ok 13) Depending on the success): mytest :: hello (); eight, at this time you You should be able to see the Success Call from Perl To C Libray!

Oh, get it!

转载请注明原文地址:https://www.9cbs.com/read-2584.html

New Post(0)