在两个 XS Perl 模块之间共享 C 函数

Sharing C functions between two XS Perl modues

我有一个 Perl 模块 A,它是一个基于 XS 的模块。我有一个 A.xs 文件和一个 aux_A.c 文件,其中有一些标准 C 函数。我使用 DynaLoader,它工作文件。

现在,我有一个新模块 B,它也是一个 XS 模块。我还有 B.xs 文件和 aux_B.c 文件。现在,我希望 aux_B.c 文件中定义的标准 C 函数能够使用 aux_A.c 文件中定义的函数。

一个选择是让A模块创建一个标准C库,linkB模块用它。但我试图摆脱这种选择。

还有别的路可以走吗?

我目前得到的是 DynaLoader 在尝试加载 B.so 库时抱怨未定义的符号。

谢谢 阿尔贝托

要使模块 A 使用 DynaLoader 导出其 C 符号,您必须将以下内容添加到 A.pm:

sub dl_load_flags { 1 }

不幸的是,这没有很好的记录。请参阅 this thread on PerlMonks and the DynaLoadersource code for more details. The effect of the flag is to set RTLD_GLOBAL when loading A.so with dlopen 使其符号可用于其他共享对象。