View previous topic :: View next topic |
Author |
Message |
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 521
|
Posted: Sun Sep 22, 2024 11:19 am Post subject: Fussy, pedantic issue with ncurses libraries |
|
|
Hi folks
It seems that the way I installed Gentoo, I ended up with libnursesw.so separated from libtinfow.so. I understand that ncurses can be built this way, or with these libraries combined. So far as I can see, most other Linux distributions have them combined.
My applications that use ncursesw have a single set of Makefiles that work on many Linux platforms -- Fedora, Ubuntu, Raspberry Pi at least -- but they don't work on Gentoo, because they don't explicitly link libtinfow.so, because they don't need to.
The solution is simple, in principle -- just modify all the Makefiles to have '-lncursesw -ltinfow', rather than just '-lnursesw'. But this means that I can no longer maintain a single set of Makefiles for all Linux platforms.
I'm curious whether this split between libncurses and libtinfo is peculiar to the way I set up Gentoo, or whether it will always be like that on a Gentoo system.
And if it will always be like that, I'm wondering if there's some non-ugly way I can modify my makefiles so that the link includes -ltinfow only on Gentoo. Or, perhaps, only on systems where this library exists. I can think of some ugly ways to do this, but surely there is some elegant way?
Incidentally, there seems to have been a fair bit of discussion of this point about ten years ago, and I don't think the Gentoo way of handling libncursesw is accidental. But it does seem to be out of line with other Linux variants.
BR, Lars. |
|
Back to top |
|
|
sam_ Developer
Joined: 14 Aug 2020 Posts: 1961
|
Posted: Sun Sep 22, 2024 11:24 am Post subject: |
|
|
You should use pkg-config instead, not hardcoding libraries: LIBS = $(pkg-config --libs ncursesw).
Anyway, see https://bugs.gentoo.org/457530. There's some more detailed discussion somewhere but I can't dig it up right now.
If you look at the Fedora packaging, they use a linker script hack to try to hide the issue.
Mod edit: Trailing period exorcised from the above URL. — JRG |
|
Back to top |
|
|
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 521
|
Posted: Sun Sep 22, 2024 4:57 pm Post subject: |
|
|
sam_ wrote: | You should use pkg-config instead, not hardcoding libraries: |
Thanks. It's good to know, I guess, that I'm not the first person to see this problem. It doesn't look like it's going to be fixed, however; from the discussion in the bug, it's not even clear to me what a fix would look like.
The problem with pkg-config is that it doesn't work on Raspberry Pi. Well, you can install the binary, but none of the .pc files are present, so it won't work. It doesn't work on Cygwin either, although I suspect I'm the only person on Earth still using Cygwin. So I'd still need different Makefiles for different platforms.
Oh, well. Not a show-stopper.
BR, Lars. |
|
Back to top |
|
|
sam_ Developer
Joined: 14 Aug 2020 Posts: 1961
|
Posted: Sun Sep 22, 2024 5:07 pm Post subject: |
|
|
The bug is discussion of moving towards the current setup, not away!
You can absolutely get pkg-config files on Raspbian and I'm 95+% sure they work on Cygwin.
(You can also do something like: LIBS = $(shell pkg-config --libs ... || echo -lncursesw ...) anyway.) |
|
Back to top |
|
|
eschwartz Developer
Joined: 29 Oct 2023 Posts: 223
|
Posted: Sun Sep 22, 2024 5:42 pm Post subject: |
|
|
lars_the_bear wrote: |
Thanks. It's good to know, I guess, that I'm not the first person to see this problem. It doesn't look like it's going to be fixed, however; from the discussion in the bug, it's not even clear to me what a fix would look like. |
The fix is to use either one of:
- a real build system
- a Makefile that runs a real dependency detector, that is to say, runs pkg-config
Many people have seen your problem, and solved it by using pkg-config. No one has had a problem of pkg-config, and solved it by hardcoding -lncurses, because that's not a solution.
Upstream ncurses implements this configuration and requires that you use pkg-config to correctly link.
Your option, if you do not wish to use pkg-config, is to run `ncurses6-config --cflags --libs`.
There is no third option.
lars_the_bear wrote: |
The problem with pkg-config is that it doesn't work on Raspberry Pi. Well, you can install the binary, but none of the .pc files are present, so it won't work. It doesn't work on Cygwin either, although I suspect I'm the only person on Earth still using Cygwin. So I'd still need different Makefiles for different platforms.
|
Certainly, Cygwin installs pkg-config files for ncurses. The Raspberry Pi doesn't, because the Raspberry Pi isn't an operating system, it's a hardware device upon which you *install* an operating system. If you mean to say it doesn't work on the Raspbian operating system, it is my pleasure to inform you that they, too, install pkg-config files for ncurses. It's right there in http://archive.raspbian.org/raspbian/pool/main/n/ncurses/libncurses-dev_6.5-2_armhf.deb
You mention "you can install the binary, but none of the .pc files are present, so it won't work". This comment alarms me, because it implies you installed the ncurses binary, but not the ncurses development package, including the ncurses *headers*. So how did you even compile your software against ncurses???
The same package provides both ncurses development headers and ncurses development pkg-config files (and the ncurses6-config script), so if you can compile against the headers you can also compile against the pkg-config files. |
|
Back to top |
|
|
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 521
|
Posted: Mon Sep 23, 2024 8:04 am Post subject: |
|
|
@eschwarz
Thank you. But the reason I don't use pkg-config is that I've spent too much time working on minimal and embedded platforms where it isn't present, or doesn't work. I can install gcc and make on Android, for example, but I don't want the hassle of installing all the extra infrastructure that would make pkg-config work. It didn't work properly with Cygwin when I last tried it, nor with the DietPi Raspberry Pi distribution. Admittedly, I haven't used either of these for some time, so the situation might have improved. Still, as a matter of principle, I don't put anything in a Makefile that couldn't be satisfied by Busybox.
In any case, I'm not really looking for a solution, because the solution is a one-line change in a few Makefiles. I appreciate that the use of pkg-config or other build infrastructure would relieve the problem for most users. I was just interested to know whether Gentoo was different in its ncurses provision from the other mainstream Linux distributions I've used, or whether I had just set something up wrongly. I certainly haven't used every Linux distribution that exists, and it's possible that they all differ from one another in this respect.
BR, Lars. |
|
Back to top |
|
|
eschwartz Developer
Joined: 29 Oct 2023 Posts: 223
|
Posted: Mon Sep 23, 2024 3:59 pm Post subject: |
|
|
lars_the_bear wrote: | @eschwarz
Thank you. But the reason I don't use pkg-config is that I've spent too much time working on minimal and embedded platforms where it isn't present, or doesn't work. I can install gcc and make on Android, for example, but I don't want the hassle of installing all the extra infrastructure that would make pkg-config work. It didn't work properly with Cygwin when I last tried it, nor with the DietPi Raspberry Pi distribution. Admittedly, I haven't used either of these for some time, so the situation might have improved. Still, as a matter of principle, I don't put anything in a Makefile that couldn't be satisfied by Busybox. |
Debian has produced a separate termlib since 2011, and Fedora since 2007. Gentoo since 2013.
DietPi seems to be based on Debian, so should have separate termlib just like Debian does.
Cygwin doesn't use a separate termlib.
I reiterate that you cannot make any assumption about -lncurses being sufficient, since it will not be.
pkg-config requires no "all the extra infrastructure". It works, and works properly with Cygwin and Debian, as long as you install *both* the pkg-config package and the development headers of the libraries you use.
But if you really dislike pkg-config that much, you can still use ncurses6-config --cflags --libs.
lars_the_bear wrote: |
In any case, I'm not really looking for a solution, because the solution is a one-line change in a few Makefiles. I appreciate that the use of pkg-config or other build infrastructure would relieve the problem for most users. I was just interested to know whether Gentoo was different in its ncurses provision from the other mainstream Linux distributions I've used, or whether I had just set something up wrongly. I certainly haven't used every Linux distribution that exists, and it's possible that they all differ from one another in this respect.
|
It's not "build infrastructure", it's one program and it relieves it for all users.
Again, this is upstream ncurses behavior and having a separate termlib is pretty standard.
On operating systems that don't use a separate termlib, they still ship ncurses6-config as well as `pkg-config --cflags --libs ncurses`, and some of them also provide a "libtinfo.so" symlink to libncurses.so in order to make -ltinfo still work. Probably cygwin should start doing the same and consider it a bugfix.
I know that Adelie, Alpine, Arch, Chimera, GoboLinux, Homebrew, Mandriva, and Void all configure without a separate termlib, but also provide the compat symlinks.
Debian, Fedora, FreeBSD, Gentoo, Mageia, OpenSUSE, GUIX configure with a separate termlib.
Crux, Cygwin, MSYS2 are (broken and) devoid of the symlinks.
On every one of these systems, pkg-config files are available. On every one of those systems, ncurses6-config is available.
Hardcoding "-lncurses -ltinfo" works most places, but not everywhere.
Hardcoding "-lncurses" fails on nearly all systems by install count (if only because of the Debian + Fedora combo)
Using Code: | CURSES_CFLAGS = $(shell pkg-config --cflags ncurses || echo "")
CURSES_LIBS = $(shell pkg-config --libs ncurses || echo -lncurses)
|
works everywhere, even on Android.
You are the second person I've ever met who was afraid to use pkg-config to detect ncurses. The first person insisted that the "pkg-config || echo" approach cannot be used because it would make pkg-config *mandatory* for building the Android bootstrap, which is apparently not acceptable because AOSP does not permit GPL software in its core, even though pkg-config is licensed with the ISC license and not the GPL:
Code: | $ equery belongs /usr/bin/pkg-config
* Searching for /usr/bin/pkg-config ...
dev-util/pkgconf-2.2.0 (/usr/bin/x86_64-pc-linux-gnu-pkgconf)
dev-util/pkgconf-2.2.0 (/usr/bin/pkg-config -> x86_64-pc-linux-gnu-pkg-config)
$ equery meta --license dev-util/pkgconf
* dev-util/pkgconf [gentoo]
ISC
|
Also, even though the shell "||" fallback construct per definition means that the left-hand side is optional and only used when available and working. |
|
Back to top |
|
|
lars_the_bear Guru
Joined: 05 Jun 2024 Posts: 521
|
Posted: Mon Sep 23, 2024 8:13 pm Post subject: |
|
|
@eschwarz
Thank you; but you've offered a very thorough defence to a criticism I never made
I just wondered if Gentoo was different from what I was familiar with, or whether I'd set it up wrongly. It's different; fine, I'll deal with it.
But thank you for you detailed response, all the same.
BR, Lars. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|