部署使用 PCRE 库的 C 应用程序

发布于 2024-08-02 16:38:33 字数 284 浏览 2 评论 0原文

我编写了一个使用 PCRE 库的 C 应用程序。一切都在我自己的电脑上运行。但是,当我将二进制文件复制到另一台计算机并运行它时,它会出现以下错误:

/libexec/ld-elf.so.1: 未找到“myapp”所需的共享对象“libpcre.so.0”

I我知道我可以通过在目标计算机上安装 PCRE 库来使其工作。但是,我想知道是否有更方便的方法来做到这一点? (只是复制一些 lib 文件?)

我尝试复制 libpcre.so.0 文件,但它不起作用。

任何帮助表示赞赏! 谢谢,

I wrote a C app that uses the PCRE library. Everything works on my own computer. However, when I copy the binary over to another computer and run it, it gives the following error:

/libexec/ld-elf.so.1: Shared object "libpcre.so.0" not found, required by "myapp"

I know I can probably get it to work by installing the PCRE lib on the target computer. However, I'm wondering if there's a more convenient way of doing this? (just copying over a few lib files?)

I tried to copy over the libpcre.so.0 file, but it didn't work.

Any help is appreciated!
Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

追星践月 2024-08-09 16:38:33

最好安装它或静态链接它。当然,前者对资源的消耗较小。确保兼容性的最佳方法是为目标系统构建包,指定所有依赖项(当然取决于发行版)。

It's better to either install it or link it in statically. The former, of course, is lighter on resources. The best way to ensure compatibility would be to build the package for target system, specifying all dependencies (depends on the distribution, of coursE).

雨轻弹 2024-08-09 16:38:33

正如 @hacker 所说,您要么必须确保在目标计算机上安装 PCRE,要么必须使用静态库(libpcre.a 而不是 libpcre.so)在开发机器上。这也可能意味着您需要使用静态库构建 PCRE,并且必须使用正确的编译时选项来引入静态库。一种相对简单的方法是在编译器命令行上指定 /usr/lib/libpcre.a。理想情况下,您也应该避免在命令行上包含 -lpcre - 当然,您希望静态库出现在共享库之前。

由于符号链接问题,您的副本可能会失败。您通常链接到一个文件,例如:

/usr/lib/libpcre.so

但这是指向版本化库的符号链接,例如:

/usr/lib/libpcre.so.0

或者它也可以以相反的方式工作。如果您使用 tar 来复制内容,则可能复制了符号链接。

理想情况下,您将 PCRE 安装在系统目录中 - 但这样做需要 root 权限。您还必须小心确保不会用旧版本覆盖更新版本的 PCRE。您还希望避免强迫用户设置 LD_LIBRARY_PATH 环境变量(或其等效变量),或强迫他们使用配置程序(ld.so.conf?)。

As @hacker said, you either have to ensure that you install PCRE on the target machine or you have to use a static library (libpcre.a instead of libpcre.so) on the development machine. That might also mean you need to build PCRE with a static library, and you'd have to use the correct compile time options to pull in the static library. One relatively easy way to do it is to specify /usr/lib/libpcre.a on the compiler command line. Ideally, you'd avoid including -lpcre on the command line too - certainly, you'd want the static library to appear ahead of the shared library.

Your copy may have failed because of issues with symlinks. You usually link to a file such as:

/usr/lib/libpcre.so

but that is a symlink to a versioned library such as:

/usr/lib/libpcre.so.0

Or it could work the other way around. If you were using tar to copy things, you may have copied a symlink.

Ideally, you install PCRE in a system directory - but doing that requires root privileges. You also have to be careful to ensure that you don't overwrite a more recent version of PCRE with your older version. You also want to avoid forcing users into setting the LD_LIBRARY_PATH environment variable (or its equivalents), or forcing them to use the configuration program (ld.so.conf?).

尛丟丟 2024-08-09 16:38:33

您应该能够复制它,然后将环境变量 LD_LIBRARY_PATH 设置为它所在的文件夹,甚至创建一个设置此环境变量的 shell 脚本,然后启动您的程序,如下所示

LD_LIBRARY_PATH=. ./your_program

检查 程序库操作方法

You should be able to copy it and then set the envvar LD_LIBRARY_PATH to the folder where it exists, or even create a shell script that sets this envvar then launches your program as follows

LD_LIBRARY_PATH=. ./your_program

Check the Program Library How To

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文