2

I want to use Tmux on a scientific computing cluster node, but it's not available in any of the Environment Modules that I can see. So I went about to build it from source, without root access. .configure needed libevent, so I successfully downloaded and built libevent 2.1 in my home directory. However, I don't know how to specify libevent in Tmux's configure script. How can I do this?

NOTE: This question is very similar to Why can't gcc find libevent when building tmux from source?, but I'm using libevent 2.1.

Hintron
  • 131

3 Answers3

1

As mentioned in Why can't gcc find libevent when building tmux from source?, there is no with-libevent=dir option. So do the following when configuring Tmux:

DIR="$HOME/path/to/libevent"
./configure CFLAGS="-I$DIR/include" LDFLAGS="-L$DIR/.libs"

Note that it's .libs, not lib. I assume this is a change in libevent 2.1.

This will get it to pass configure checks and compile. However, you're not out of the woods yet. If you only do this, then when you attempt to run tmux, you'll get this error:

error while loading shared libraries: libevent-2.1.so.6: cannot open shared object file: No such file or directory

This blog post has the solution - append the .libs path to LD_LIBRARY_PATH, like so:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/path/to/libevent/.libs

Now, to get this to "stick" the next time you login, paste the line above into your ~/.bashrc file. If you merely run the command in your terminal, it will only last for that session.

Hintron
  • 131
0

You can use pkg-config to do this easily.

First, build libevent. In this example we will be installing libevent to /tmp/libevent - you don't have to create this directory manually, it will be created automatically during the build process. You do not need to be root to run make install:

$ ./autogen.sh
$ ./configure  --prefix=/tmp/libevent
$ make
$ make install

You should now have /tmp/libevent/lib/pkgconfig/libevent.pc:

$ cat /tmp/libevent/lib/pkgconfig/libevent.pc
#libevent pkg-config source file

prefix=/tmp/libevent
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: libevent
Description: libevent is an asynchronous notification event loop library
Version: 2.2.0-alpha-dev
Requires:
Conflicts:
Libs: -L${libdir} -levent
Libs.private:
Cflags: -I${includedir}

Notice that prefix is set to the directory we passed as an argument to ./configure.

Before building tmux add /tmp/libevent/lib/pkgconfig to PKG_CONFIG_PATH:

$ export PKG_CONFIG_PATH=/tmp/libevent/lib/pkgconfig:$PKG_CONFIG_PATH
$ pkg-config --cflags --libs libevent
-I/tmp/libevent/include -L/tmp/libevent/lib -levent

And then build tmux normally:

$ ./autogen.sh
$ ./configure
$ make

Notice than in order to actually start tmux with your custom libevent you have to set LD_LIBRARY_PATH correctly:

$ ldd ./tmux
        linux-vdso.so.1 (0x00007ffce3d92000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007f2f1d77e000)
        libncurses.so.5 => /lib64/libncurses.so.5 (0x00007f2f1d527000)
        libevent-2.2.so.1 => not found
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f2f1d30b000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2f1cf42000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f2f1cd3d000)
        /lib64/ld-linux-x86-64.so.2 (0x000055cdf0697000)
$ ./tmux
./tmux: error while loading shared libraries: libevent-2.2.so.1: cannot open shared object file: No such file or directory
$ LD_LIBRARY_PATH=/tmp/libevent/lib ./tmux -V
tmux master

EDIT:

In order to get away with setting LD_LIBRARY_PATH you can set rpath when building tmux:

$ ./configure LDFLAGS="-Wl,-rpath=/tmp/libevent/lib"
$ make
$ ldd ./tmux
        linux-vdso.so.1 (0x00007ffcc6de1000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007fbe121a4000)
        libncurses.so.5 => /lib64/libncurses.so.5 (0x00007fbe11f4c000)
        libevent-2.2.so.1 => /tmp/libevent/lib/libevent-2.2.so.1 (0x00007fbe11cf7000)
        libresolv.so.2 => /lib64/libresolv.so.2 (0x00007fbe11adc000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fbe11712000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fbe1150e000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fbe112f1000)
        /lib64/ld-linux-x86-64.so.2 (0x000055f057ef4000)
 $ ./tmux -V
 tmux master
0

Encountered similar problem when running tmux even after installing libevent-2.1.so.7. Creating symlink of the installed file to /lib64/ directory worked for me.

$sudo ln -s /usr/local/lib/libevent-2.1.so.7.0.0 /lib/x86_64-linux-gnu/libevent-2.1.so.7

$ldd tmux
    linux-vdso.so.1 (0x00007fff6f9fe000)
    libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f675b5eb000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f675b3c1000)
    libevent-2.1.so.7 => /lib/x86_64-linux-gnu/libevent-2.1.so.7 (0x00007f675b16b000)
    libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f675af50000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f675ab5f000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f675a940000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f675ba9f000)
Karlz
  • 1