Deploying C app that uses the PCRE library

2019-02-25 05:03发布

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,

3条回答
Evening l夕情丶
2楼-- · 2019-02-25 05:24

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).

查看更多
成全新的幸福
3楼-- · 2019-02-25 05:31

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?).

查看更多
beautiful°
4楼-- · 2019-02-25 05:40

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

查看更多
登录 后发表回答