如何从Perl程序中调用C函数?

时间:2013-02-28 13:34:20

标签: perl

test.c

int sum(int a, int b)
{
    return (a+b);
}

test.pl

# how do I call sum here?

2 个答案:

答案 0 :(得分:14)

use Inline C => <<'__END_OF_C__';

    int sum(int a, int b)
    {
        return (a+b);
    }

__END_OF_C__

say sum($x,$y);

答案 1 :(得分:0)

您需要XS。它非常复杂,所以最好查看它的官方手册和教程页面:

http://perldoc.perl.org/perlxstut.html

http://perldoc.perl.org/perlxs.html