[英]Sharing C functions between two XS Perl modues
I have a Perl module A
that is a XS based module. 我有一个Perl模块A
,它是一个基于XS的模块。 I have an A.xs
file, and an aux_A.c
file, where I have some standard C functions. 我有一个A.xs
文件和一个aux_A.c
文件,其中有一些标准的C函数。 I use DynaLoader
, and it works file. 我使用DynaLoader
,并且可以工作。
Now, I have a new module B
, that is also a XS module. 现在,我有了一个新模块B
,它也是一个XS模块。 I also have the B.xs
file, and the aux_B.c
file. 我也有B.xs
文件和aux_B.c
文件。 Now, I want that a standard C function defined in aux_B.c
file to be able to use a function defined in aux_A.c
file. 现在,我希望aux_B.c
文件中定义的标准C函数能够使用aux_A.c
文件中定义的函数。
One option is to make A module to create a standard C library, and link B module with it. 一种选择是使A模块创建标准C库,并将B模块与其链接。 But I was trying to get away from that option. 但是我试图摆脱这种选择。
Is there any other way to go? 还有其他方法吗?
What I am currently getting is DynaLoader complaining on undefined symbol when trying to load the B.so
library. 我现在得到的是B.so
在尝试加载B.so
库时抱怨未定义的符号。
Thanks Alberto 谢谢阿尔贝托
To make module A export its C symbols with DynaLoader
, you have to add the following to A.pm
: 为了让模块A出口其C符号与DynaLoader
,你必须添加以下A.pm
:
sub dl_load_flags { 1 }
This is badly documented, unfortunately. 不幸的是,这没有充分记录。 See this thread on PerlMonks and the DynaLoader
source code for more details. 有关更多详细信息,请参见PerlMonks和DynaLoader
源代码 上的该线程 。 The effect of the flag is to set RTLD_GLOBAL
when loading A.so
with dlopen
which makes its symbols available to other shared objects. 该标志的作用是在使用dlopen
加载A.so
时设置RTLD_GLOBAL
,这使其符号可用于其他共享对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.