简体   繁体   English

如何告诉 MakeMaker 准确添加我想要的库?

[英]How to tell MakeMaker to add exactly the libraries I want?

I'm using XS to create a Perl Module which uses a C library.我正在使用 XS 创建一个使用 C 库的 Perl 模块。

For testing purposes, I've created a test library which has two simple functions:出于测试目的,我创建了一个测试库,它具有两个简单的功能:

void kzA()  (does a simple printf)
void kzB(int i, char *str) (does a printf of the received parameters)

I've also created some glue in XS, in order, for now, to access the kzA() function: (I'm only showing the function itself, but the includes are there, too, in the XS)我还在 XS 中创建了一些胶水,以便现在访问 kzA() 函数:(我只展示了函数本身,但包含也在 XS 中)

void
ka()
    CODE:
        printf("Before kzA()\n");
        kzA();
        printf("After kzA()\n");

So, I compiled the test library as fc.so, and it is in the same directory as my xs file, and my Makefile.PL (/workspace/LirePivots)因此,我将测试库编译为 fc.so,它与我的 xs 文件和我的 Makefile.PL (/workspace/LirePivots) 位于同一目录中

In my Makefile.PL, I set the LIBS key to ['-L/workspace/LirePivots -l:fc.so'], but when executing it with perl (perl Makefile.PL), it says "Warning (mostly harmless): No library found for -l:fc.so" It then writes a Makefile which does NOT mention said library.在我的 Makefile.PL 中,我将 LIBS 键设置为 ['-L/workspace/LirePivots -l:fc.so'],但是在使用 perl (perl Makefile.PL) 执行它时,它显示“警告(主要是无害的) : 没有找到 -l:fc.so 的库”然后它写了一个没有提到所述库的 Makefile。 And then, after compiling (with "make") and installing (with "sudo make install"), when I run my test script which calls the ka() function from my module, I get the line "before", but the kzA() function isn't called, obviously, because it cannot find the kzA symbol, and the program stops there.然后,在编译(使用“make”)和安装(使用“sudo make install”)之后,当我运行从我的模块调用 ka() 函数的测试脚本时,我得到了“before”行,但是 kzA () 函数没有被调用,很明显,因为它找不到 kzA 符号,程序就停在那里。

Creating a C test program which I would link with the very same arguments (-l:fc.so -L/workspace/LirePivots) does work, and, as long as I put the path in LD_LIBRARY_PATH, it finds the function and runs it correctly.创建一个 C 测试程序,我将使用相同的参数 (-l:fc.so -L/workspace/LirePivots) 链接它确实有效,并且只要我将路径放在 LD_LIBRARY_PATH 中,它就会找到该函数并运行它正确。

I also tried renaming the library libfc.so, and changing the -l part to "-lfc", but it didn't work either.我还尝试重命名库 libfc.so,并将 -l 部分更改为“-lfc”,但它也不起作用。 It never manages to find the library.它永远无法找到图书馆。

Does anyone know what I do wrong ?有谁知道我做错了什么?

EDIT: As requested, I created a minimum example: https://github.com/kzwix/xsTest To run it, you'll need to have a Linux with Perl 5, along with XS (package perl-devel, on Redhat).编辑:根据要求,我创建了一个最小示例: https : //github.com/kzwix/xsTest要运行它,您需要有一个带有 Perl 5 的 Linux 和 XS(包 perl-devel,在 Redhat 上) . And a C compiler, and make, obviously.还有一个 C 编译器和 make,很明显。

Ok, I still don't know the reason why it wouldn't find the library.好吧,我仍然不知道它为什么找不到图书馆的原因。 But I found a workaround:但我找到了一个解决方法:

By adding the test library as "libfc.so" to /usr/lib, then running "sudo ldconfig", the library got added to the cache (when named fc.so, even if in /usr/lib, ldconfig would not add it. Also, it wouldn't work with symbolic links, either, I had to really copy it there).通过将测试库作为“libfc.so”添加到 /usr/lib,然后运行“sudo ldconfig”,库被添加到缓存中(当命名为 fc.so 时,即使在 /usr/lib 中,ldconfig 也不会添加它。另外,它也不适用于符号链接,我不得不将它复制到那里)。

After the library got added to the cache, "perl Makefile.PL" would still not find the library.图书馆得到了添加到缓存后,“perl的Makefile.PL”仍然找不到库。 I had to use "-L/usr/lib" in addition to "-lfc" for it to at long last find the library, and "agree" to add the parameters to the link step of the library.除了“-lfc”之外,我还必须使用“-L/usr/lib”才能最终找到库,并“同意”将参数添加到库的链接步骤。

After this happened, I could compile with "make", and executing the test program did work as originally intended (I saw both the "before" and "after" printf, and I saw the one from the function in the kzA() function from libfc.so)发生这种情况后,我可以使用“make”进行编译,并且执行测试程序确实按预期工作(我看到了“之前”和“之后”printf,我看到了 kzA() 函数中的函数来自 libfc.so)

Thanks Håkon Hægland for helping.感谢 Håkon Hægland 的帮助。

(I can't provide the Dockerfiles, they link to images internal to my organization, which I'm not allowed to share) (我无法提供 Dockerfile,它们链接到我的组织内部的图像,我不允许共享)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何告诉MakeMaker在子目录中构建XS文件? - How to tell MakeMaker to build XS files in a subdirectory? 如何在ExtUtils :: Makemaker中更改保存测试文件的目录? - How can I change the directory holding the test files in ExtUtils::Makemaker? 如何获得代码覆盖率的 MakeMaker 目标? - How do I get a MakeMaker target for code coverage? 如何更改MakeMaker的默认CFLAGS - How to change default CFLAGS for MakeMaker 使用Perl的ExtUtils :: MakeMaker,如何使用与XS模块相同的设置来编译可执行文件? - Using Perl's ExtUtils::MakeMaker, how can I compile an executable using the same settings as my XS module? ExtUtils::MakeMaker:如何为测试和/或安装指定二进制可执行文件先决条件? - ExtUtils::MakeMaker: how do I specify a binary executable prerequisite for test and/or installation? Perl-在测试中将Devel :: Cover添加到ExtUtils :: MakeMaker - Perl - add Devel::Cover to the ExtUtils::MakeMaker in make test 如何在Perl中向库添加相对路径? - How can I add relative paths to libraries in perl? 如何在Perl的ExtUtils:MakeMaker中处理外部依赖关系 - How to handle external dependencies in perl's ExtUtils:MakeMaker 如何在使用ExtUtils :: MakeMaker时更改脚本/模块中的变量字符串 - How to change a variable string in scripts/modules when using ExtUtils::MakeMaker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM