aristocratos / btop

A monitor of resources
Apache License 2.0
21.38k stars 656 forks source link

[BUG] GPU compilation should enable the linker flag -ldl by default #730

Closed rahulaggarwal965 closed 10 months ago

rahulaggarwal965 commented 10 months ago

Describe the bug

On Ubuntu 20.04 (g++-10), when compiling from the v1.3.0 tag (I also tested on main) with GPU_SUPPORT enabled (NVIDIA), the default makefile does not include the linker flag -ldl and therefore does not compile. Adding -ldl solves this problem.

To Reproduce

git clone https://github.com/aristocratos/btop.git
cd btop
git checkout v1.3.0 (optional)
CXX=g++-10 make

I expect the compilation to resolve successfully. Below I have attached a screenshot and a log of the error message. image

Text Log ``` /usr/bin/ld: /tmp/btop.c8wIWg.ltrans16.ltrans.o: in function `Shared::init()': :(.text+0x6608): undefined reference to `dlopen' /usr/bin/ld: :(.text+0x6629): undefined reference to `dlopen' /usr/bin/ld: :(.text+0x663e): undefined reference to `dlerror' /usr/bin/ld: /tmp/btop.c8wIWg.ltrans22.ltrans.o: in function `Gpu::Nvml::init()::{lambda(char const*)#1}::operator()(char const*) const [clone .constprop.0]': :(.text+0x1b6f): undefined reference to `dlsym' /usr/bin/ld: :(.text+0x1b77): undefined reference to `dlerror' /usr/bin/ld: /tmp/btop.c8wIWg.ltrans22.ltrans.o: in function `Gpu::Rsmi::init()::{lambda(char const*)#1}::operator()(char const*) const [clone .constprop.0]': :(.text+0x1c6f): undefined reference to `dlsym' /usr/bin/ld: :(.text+0x1c77): undefined reference to `dlerror' /usr/bin/ld: /tmp/btop.c8wIWg.ltrans25.ltrans.o: in function `Gpu::Rsmi::init() [clone .isra.0]': :(.text+0x8497): undefined reference to `dlopen' /usr/bin/ld: :(.text+0x84b1): undefined reference to `dlerror' /usr/bin/ld: /tmp/btop.c8wIWg.ltrans25.ltrans.o: in function `Gpu::Nvml::shutdown() [clone .isra.0]': :(.text+0x1c19): undefined reference to `dlclose' /usr/bin/ld: /tmp/btop.c8wIWg.ltrans25.ltrans.o: in function `Gpu::Rsmi::shutdown() [clone .isra.0]': :(.text+0x1ce7): undefined reference to `dlclose' collect2: error: ld returned 1 exit status make: *** [Makefile:350: btop] Error 1 ```

However, when I compile using the following command:

LDFLAGS=-ldl make

btop compiles successfully. image

This seems to be an easy fix, but I would defer to you on whether this fix is only needed on certain platforms/distributions/kernel versions.

Info (please complete the following information):

imwints commented 10 months ago

Read the README.md and search for similar issues before posting a bug report!

704 #725

rahulaggarwal965 commented 10 months ago

Since the Makefile doesn't do it I wouldn't like to do this to support (compiling against) some ancient glibc. Being written with C++-20 btop is dependent on recent compilers anyway so it wouldn't make much sense to support (compiling against) older libc's while requiring new compilers.

Sounds good. Since it looks like you want to have this behavior explicitly, I will close this for now.