Linux – How do I build ‘./configure && make &make install’ software for custom libraries that I also build?

How do I build ‘./configure && make &make install’ software for custom libraries that I also build?… here is a solution to the problem.

How do I build ‘./configure && make &make install’ software for custom libraries that I also build?

I’m building tmux-2.0 from source on a very ordinary Linux host. The first attempt failed because the installed version of libevent was older than required, so I went ahead and downloaded from source and built libevent-2.0.22 writing time) first.

libevent builds flawlessly, I think I can retry building tmux with the following code:

PKG_CONFIG_PATH=$PATH_TO_MY_BUILT_LIBEVENT/lib/pkgconfig ./configure ...

The above call succeeds, and the subsequent make and make install also succeed.

Running my newly built tmux, however, libevent-2.0.so.5 is not surprising due to lack of shared objects:

tmux: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory

I think building against a custom library means it will also be used at runtime? ldd on my tmux to me:

linux-vdso.so.1 =>  (0x00007fff8f5ff000)
libutil.so.1 => /lib64/libutil.so.1 (0x0000003cf8800000)
libncurses.so.5 => /lib64/libncurses.so.5 (0x0000003cf7e00000)
libevent-2.0.so.5 => not found
librt.so.1 => /lib64/librt.so.1 (0x0000003ce8600000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x0000003cea200000)
libc.so.6 => /lib64/libc.so.6 (0x0000003ce7600000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003cf7200000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003ce7e00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003ce8200000)
/lib64/ld-linux-x86-64.so.2 (0x0000003ce7200000)

Therefore, libevent-2.0.so.5 was not found.

I DON’T KNOW IF I NEED TO RESORT TO SETUP, I DON’T KNOW, LIBS,

LDFLAGS, OR SOME OTHER VARIABLE OR SWITCH TO THE CONFIGURE SCRIPT, SO, I DON’T KNOW, THE PATH TO MY NEW LIBEVENT IS EMBEDDED IN THE TMUX BINARY, BY What does LD provide?

I don’t have root access – university Linux workstation – frankly, I don’t think I need to. I also don’t want to mess around with LD_LIBRARY_PATH or something like that. It can be said that LD_LIBRARY_PATH=$PATH_TO_MY_LIBEVENT/lib tmux works fine. But I want it to work “by default”, locating and using my libevent.

I guess this solution works with almost all software that uses the GNU Build System. What is the right thing to do here?

Solution

You built against a library, but the system doesn’t know where the library is. Since you don’t want to install the library, but leave it where you built it, you can work around it using the linker’s -rpath= option — it embeds a search path Put the library in the executable.

Just rebuild your app and add it to your LDFLAGS, e.g. LDFLAGS="-rpath=/home/mypath/to/libevent" (but note that it is a linker option, and it is possible that gcc itself is used as a linker in makefiles – gcc does not know this option, then you need to write like this.) LDFLAGS="-wl,-rpath=/home/mypath/to/libevent" forces gcc to pass the option to the actual linker).

By the way, you can actually even change the rpath without even having to recompile the application — there’s a tool patchelf For that job.

Related Problems and Solutions