reddit / emacs

Compiling Emacs 28.1 with multiple versions of gnutls

Tohiko · 2022-04-09 16:10
I have an old version of gnutls on my system, which I cannot uninstall (no sudo permissions). Instead, I installed a local version in my home directory and set `PKG_CONFIG_DIR` to point to it so that when I call `pkg-config -libs gnutls` I get the correct paths ``` -L/home/user/.local/stow/gnutls/lib -lgnutls ``` I then tried compiling emacs from source by calling `./configure` and `make` but got a linking error. ``` ld: gnutls.o: in function `Fgnutls_peer_status': /home/user/emacs/src/gnutls.c:1505: undefined reference to `gnutls_session_etm_status' ``` Upon further inspection, I found that the linking command is something like this ``` gcc -o temacs.tmp {CFLAGS} ... gnutls.o ... -L/usr/lib64 -lgtk-3 ... -L/home/user/.local/stow/gnutls/lib -lgnutls ... ``` The problem is that the old `gnutls` library in `/usr/lib64` take precedence over the custom directory that is specified right before linking `gnutls`. I resolved this by changing the `LIBGNUTLS_CFLAGS` to include `-L /home/user/.local/stow/gnutls/lib` so that the this directory takes precedence over all other subsequent directories. This feels too hacky. Is there a better way to resolve?
[deleted] · 2022-04-09 19:35
[deleted]
AngryFilament · 2022-04-09 22:31
That's the intended solution - no need to change the makefiles or any compile scripts, it's easily revertible, and surgically makes the exact change you require.
paretoOptimalDev · 2022-04-10 00:44
So it's heavy, but minimal work: Install the Nix package manager from nixos.org and install emacs from there but keep installing elisp packages as you normally do. That's my quick fix for this type of issue on Linux machines these days since it always works. Someone might have a better solution, but heres one that should work.
[deleted] · 2022-04-10 01:25
[deleted]
Tohiko · 2022-04-11 09:54
Yes, I do think this is a workable solution. But I can also imagine running into this issue again with another library and having to figure out which library is actually being used depending on previous paths in the linking command. I thought that I might be doing something wrong with my overall configuration/setup since this looks hacky and tools like `pkg-config` are supposed to do away with such hacky-ness. Nevertheless, based on the responses here it seems everything is working as intended. Thanks!