I am trying to compile a package; specifically, the plugin gkrellm-leds
for gkrellm
. I downloaded the sources from packages.ubuntu.com/source/zesty/gkrellm-leds .
After compiling and installing it, it doesn't work. The program that should use it, gkrellm
, doesn't even show it as an available plugin .
Since this is not the first time these things have happened to me, the first thing I did was
> ldd gkleds.so
linux-vdso.so.1 => (0x00007ffe15def000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2fc6f37000)
/lib64/ld-linux-x86-64.so.2 (0x0000557eb4014000)
I know that this package uses the GTK-2.0 libraries, as well as others. In fact, the source code is full of calls to functions of these libraries.
The Makefile
one in the package is:
SHELL = /bin/sh
VPATH = src:src/pixmaps
GTK_INCLUDE = `pkg-config gtk+-2.0 --cflags`
GTK_LIB = `pkg-config gtk+-2.0 --libs`
X11_LIB = -L/usr/X11R6/lib -lX11 -lXtst
LIBS = $(GTK_LIB) $(X11_LIB)
DEFINES =
LFLAGS = -shared
INCLUDES = $(GTK_INCLUDE)
CFLAGS = -ansi -pedantic -Wall -O2 -fPIC
CC = gcc
SRCS = gkleds.c
HDRS = gkleds.h
OBJS = gkleds.o
IMAGES = leds.xpm
DESTDIR =
INSTALL_PROG = install
.PHONY : clean
.PHONY : install
.PHONY : uninstall
.PHONY : test
#=======================================================================
#=======================================================================
gkleds.so : $(OBJS)
$(CC) $(LFLAGS) $(LIBS) -o $@ $<
gkleds.o : $(SRCS) $(HDRS) $(IMAGES)
$(CC) $(CFLAGS) $(INCLUDES) $(DEFINES) -c -o $@ $<
test :
$(MAKE) clean
$(MAKE) DEFINES="-DGKLEDS_DEBUG"
gkrellm --sync --demo -p gkleds.so
$(MAKE) clean
clean:
rm -rf *.o *.so* *~ \#*
rm -rf src/*~ src/\#*
install : gkleds.so
@ if [ "$$UID" -ne 0 ]; \
then PLUGIN_DIR=$$HOME/.gkrellm2/plugins; \
elif [ -e /usr/bin/gkrellm ]; \
then PLUGIN_DIR=/usr/lib/gkrellm2/plugins; \
else \
PLUGIN_DIR=/usr/local/lib/gkrellm2/plugins; \
fi; \
$(INSTALL_PROG) -d $(DESTDIR)/$$PLUGIN_DIR; \
$(INSTALL_PROG) -s gkleds.so $(DESTDIR)/$$PLUGIN_DIR; \
printf "\ngkleds installed in $$PLUGIN_DIR\n"
All build dependencies are correctly installed, as well as the pkg-config
corresponding ones:
> pkg-config gtk+-2.0 --cflags
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0/ -I/usr/include/ cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libpng16 -I/ usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/ include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2
> pkg-config gtk+-2.0 --libs
-lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype
Anyway, to be safe, I dumped the results of pkg-config
into a separate file, extra.mk
, and modified the Makefile
original to include my own, adding include extra.mk
and removing the definitions of GTK_INCLUDE
and GTK_LIB
.
After that small modification, doing make
, apart from several irrelevant warnings , shows the following:
gcc -DGKLEDS_DEBUG -ansi -pedantic -Wall -O2 -fPIC -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/ gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman -1 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I /usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -c -o gkleds. o src/gkleds.c ...
... VARIOUS WARNINGS ...
...
gcc -shared -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 - lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lX11 -lXtst -o gkleds.so gkleds.o
It can be seen how, in the last part, it calls gcc
with the correct options and libraries.
However, if I redo
> ldd gkleds.so
linux-vdso.so.1 => (0x00007ffe15def000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2fc6f37000)
/lib64/ld-linux-x86-64.so.2 (0x0000557eb4014000)
It still doesn't show GTK or any other dependencies , apart from those added by default by the gcc
.
- Why aren't references to the external libraries used by the package included?
- How do I solve it ?
Voucher. Already solved.
Googling, I ended up finding a question on StackOverflow:
gcc build links but shared library does not appear with ldd
In the accepted answer it is stated
Which, in a very loose translation on my part:
In my case, what I'm trying to compile is a ; it is not an executable and, with the option
--as-needed
, the linker directly obviates any references to external libraries. It is assumed that they will already be referenced in the executable that we use.The solution has been simple. I changed the
Makefile
:by
With this modification, the option is inverted
--as-needed
; we force the linker to include any references to external libraries.After doing
make
, the result is as expected:If library dependencies are indicated . After installing it again, if it shows in the list of available plugins in
gkrellm
, and it works correctly.Ubuntu artful update ( 10-31-17)
In this version, with
gcc -v
gcc
It doesn't recognize the option--no-as-needed
. You need to explicitly tell it that the option is for the linker . For this, and starting from theMakefile
original , the modification to be made is the following:original line:
Modified line :