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

1.6*_*618 4 perl

test.c:

int sum(int a, int b)
{
    return (a+b);
}
Run Code Online (Sandbox Code Playgroud)

test.pl:

# how do I call sum here?
Run Code Online (Sandbox Code Playgroud)

ike*_*ami 15

use Inline C => <<'__END_OF_C__';

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

__END_OF_C__

say sum($x,$y);
Run Code Online (Sandbox Code Playgroud)

  • 你可以使用Inline.它允许您指定要链接的对象.将`LIBS =>' - mymyclib'添加到`use`行. (3认同)

Fai*_*aiz 1

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

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

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