mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.61k stars 1.63k forks source link

using menu dependency, ncurses is linked twice #8867

Open andy5995 opened 3 years ago

andy5995 commented 3 years ago

When I use

dep_curses = dependency('curses')
dep_menu = dependency('menu')

then my binary is linking to ncursesw and ncurses:

$ ldd ./rmw
    linux-vdso.so.1 (0x00007fff26b7e000)
    libmenu.so.6 => /lib/x86_64-linux-gnu/libmenu.so.6 (0x00007fe53a7ba000)
    libncursesw.so.6 => /lib/x86_64-linux-gnu/libncursesw.so.6 (0x00007fe53a77f000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007fe53a750000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe53a58b000)
    libncurses.so.6 => /lib/x86_64-linux-gnu/libncurses.so.6 (0x00007fe53a561000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fe53a55b000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe53a7ef000)

Which I believe causes the menu display from my binary to be incorrect:

Screenshot_2021-06-10_14-58-51 (the highlighted entry is all white, and some of the characters are missing from the entries below it).

When I change dependency('curses') to ncurses or ncursesw, the ncurses library is only linked once, and the menu appears correctly:

Screenshot_2021-06-10_14-59-34

I think the intended behavior is that when dependency('curses') is used, it will prioritize curses or ncurses with wide-char support and use non-wide as the fall back.

For me, that's the desired behavior, and I'll only have to add a condition to my meson.build for that, right? Or am I missing something? I'm pretty inexperienced using meson...

system parameters

andy5995 commented 3 years ago

It seems that the dual-linking happens from the addition of the menu dependency.

The problem doesn't reproduce when I do it this way:

dep_curses = dependency('curses')
dep_menu = dependency('menuw', required : false)
if dep_menu.found() != true
    dep_menu = dependency('menu', required : true)
endif
$ ldd ./rmw
    linux-vdso.so.1 (0x00007ffdaad3e000)
    libmenuw.so.6 => /lib/x86_64-linux-gnu/libmenuw.so.6 (0x00007f275c561000)
    libncursesw.so.6 => /lib/x86_64-linux-gnu/libncursesw.so.6 (0x00007f275c526000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f275c4f7000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f275c332000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f275c32c000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f275c597000)
dcbaker commented 3 years ago

Hmmm, that looks like menu might depend on libncurses, If that's right I'm assuming what's happening is your build is falling back to menu (not menuw), but Meson is still selecting wide char curses?

andy5995 commented 3 years ago

Yeah, I think that's pretty much it.

Part of the problem is that I assumed that the w wouldn't be needed when using dep_menu = dependency('menu'), like it's not for curses... So yes, when I just try menu, it's not looking for menuw at all. And as you said, menu is seeing libncurses as the a dependency, so it's adding that.

dep_curses = dependency('curses')
dep_menu = dependency('menuw', required : false)
if dep_menu.found() != true
    dep_menu = dependency('menu', required : true)
endif

So what I think I need to do here is to change the condition and determine which curses was found (i.e. ncurses, ncursesw), then look for the corresponding menu dependency.

Although I'm not sure if it's correct for meson to add libncurses for the menu dependency.

My only reason for saying that is because pkg-config doesn't do it:

$ pkg-config --libs menu
-lmenu

Though another reason might be is that for menu to work, a curses dependency already needs to be found and added to the build target, so maybe it's just plain not necessary for libncurses (wide or not) to be added automatically when dependency('menu') is used. What do you think?