Why can't gcc find libevent when building tmux from source?

56,508

Solution 1

Try:

DIR="$HOME/.bin-libevent"
./configure CFLAGS="-I$DIR/include" LDFLAGS="-L$DIR/lib"

(I'm sure there must be a better way to configure library paths with autoconf. Usually there is a --with-libevent=dir option. But here, it seems there is no such option.)

Solution 2

I was having a similar problem and discovered that after running sudo yum install libevent-devel I was able to successfully make and install tmux.

EDIT: If you are installing this on a Red Hat machine, you will also need to visit the channels selection for your server on the Red Hat Network and add the RHEL Server Optional channel. This will give you access to the -devel packages for libevent (the base and supplementary channels do not provide it).

Solution 3

I had the same issue on RHEL 5.4 and actually found libevent is installed but there is no libevent.so symlink, only the real version of the library:

/usr/lib64/libevent-1.1a.so.1
/usr/lib64/libevent-1.1a.so.1.0.2

So, ln -s /usr/lib64/libevent-1.1a.so.1 /usr/lib64/libevent.so works pretty well for me without the need to install or alter anything. No idea why RedHat's libevent rpm didn't create the symlink. Maybe a bug to report?

But now, it's complaining for this: error: event.h: No such file or directory.

Solution 4

Before the configuration and compilation of tmux (or any program) you need to tell it where it can find the libraries it needs. If you have installed some library in a non-standard location, you can use the environmental variable LD_LIBRARY_PRELOAD to tell, where some libraries are located.

I your case:

$ export LD_LIBRARY_PRELOAD=$HOME/.bin-libevent/lib

And then go on with the configuration/compilation.

Later on, the binary will also need to know where your additional libraries can be found, so you'll need to place the export statement in your .bashrc (if bash is your login shell).

Solution 5

The accepted answer is good, but as of at least tmux 2.8 there is support for specifying libevent location using environment variables.

First install libevent in desired location. I used cmake because I had a problem with autoconf

cmake -DCMAKE_INSTALL_PREFIX=$HOME/usr ..
make install

Then build and install tmux:

export LIBEVENT_CFLAGS=-I${HOME}/usr/include 
export LIBEVENT_LIBS="-L${HOME}/usr/lib -levent" 
./configure --prefix=$HOME/usr
make install

The environment variable LIBEVENT_CFLAGS overrides pkg-config include settings for libevent, and LIBEVENT_LIBS overrides the linker flag settings.

Share:
56,508

Related videos on Youtube

volker
Author by

volker

Updated on September 18, 2022

Comments

  • volker
    volker over 1 year

    I want to install tmux on a machine where I don't have root access. I already compiled libevent and installed it in $HOME/.bin-libevent and now I want to compile tmux, but configure always ends with configure: error: "libevent not found", even though I tried to point to the libevent directory in the Makefile.am by modifying LDFLAGS and CPPFLAGS, but nothing seems to work.

    How can I tell the system to look in my home dir for the libevent?

    • Chili
      Chili over 6 years
      If you are on RHEL 6.x, there is a pre-compiled tmux in the repos.
  • volker
    volker over 12 years
    Thanks, but sadly this doesn't work, same error message. The version number is libevent-2.0.12 which should work
  • rozcietrzewiacz
    rozcietrzewiacz over 12 years
    Then it seems there is a problem with your libevent compilation. What does find .bin-libevent -name 'libevent.so*' show?
  • volker
    volker over 12 years
    $ find .bin-libevent -name 'libevent.so*' finds .bin-libevent/lib/libevent.so
  • rozcietrzewiacz
    rozcietrzewiacz over 12 years
    :) Then you should point at the directory $HOME/.bin-libevent/lib (updated the answer)
  • volker
    volker over 12 years
    Yes, I am afraid I already tried that as well, still no change. I am quite puzzled and frustrated.
  • Daniel Serodio
    Daniel Serodio over 12 years
    The OP didn't mention which *nix he's using. On OSX, DYLD_LIBRARY_PATH is equivalent to LD_LIBRARY_PATH on Linux.
  • Michael Mrozek
    Michael Mrozek over 11 years
    This would be the normal way to fix it, but in this case it was "a machine where I don't have root access"
  • Martin Geisse
    Martin Geisse over 11 years
    This is the approach that made make finally work. I tried setting other environment variables and setting prefix and exec-prefix, but once I included these flags stuff actually got built.
  • gkb0986
    gkb0986 over 10 years
    I got the same exact error: error: event.h: No such file or directory.
  • polym
    polym almost 10 years
    This helped me. I wasn't root and I hadn't installed the devel lib.
  • arrowill12
    arrowill12 over 9 years
    where do you get the devel lib as a tar file?
  • csl
    csl over 9 years
    I'm on RHEL 6, and I just downloaded and compiled libevent, installing it to a user folder. Then I used @Stéphane Gimenez's trick above to get it compiling. To get it running, I aliases with the LD_PRELOAD trick given by @rozcietrzewiacz: tmux='LD_PRELOAD=/opt-local/lib/libevent-2.0.so.5 /opt-local/bin/tmux'. Works like a charm!
  • lucaswxp
    lucaswxp over 8 years
    How would I go about specifying multiple directories for the flags? I tried ./configure CFLAGS="-I$DIR/include:/usr/otherdir" LDFLAGS="-L$DIR/lib:/usr/otherdir" but no success
  • Kusalananda
    Kusalananda over 7 years
    @lucaswxp CFLAGS="-Idir1 -Idir2 -Idir3" LDFLAGS="-Ldira -Ldirb -Ldirb"
  • Kusalananda
    Kusalananda over 7 years
    If you find yourself messing around with symlinks or manually copying things around in system directories, then there is a better way of doing it.
  • Kusalananda
    Kusalananda over 7 years
    LD_LIBRARY_PRELOAD is used when executing a binary. It is pretty useless for telling a linker where to find a library.
  • Mustakimur Khandaker
    Mustakimur Khandaker over 7 years
    for my fedora machine, I also required to sudo yum install ncurses-devel besides sudo yum install libevent-devel
  • luofeiyu
    luofeiyu over 7 years
    Not sure why it got downvoted. It fixed the issue for me on a CentOS system.
  • axolotl
    axolotl almost 6 years
    I used this answer and the libevent not found error went away, but now I get the same with ncurses: curses not found. My libevent as well as ncurses installations are both in $HOME/.local/
  • Jongsu Liam Kim
    Jongsu Liam Kim about 5 years
    For libevent, use LIBEVENT_CFLAGS and LIBEVENT_LIBS instead of CFLASG and LDFLAGS. For ncurse, use LIBTINFO_CFLAGS and LIBTINFO_LIBS @Aalok
  • wbadart
    wbadart about 5 years
    I also had curses installed to a custom location (I'm not an admin on the target system), and didn't realize it installs itself to the ncurses subdirectory of whatever include/ library path you specify. Odd design choice. This fixed it for me.
  • ansonl
    ansonl over 4 years
    This worked for me, but how does this work versus putting $HOME in the flag directly?