Closed ErichRitz closed 6 years ago
I don't want to introduce a dependency to pkg-config for this. Plus I'm not convinced that all systems with pkg-config, come with pkg-config definition files for the X libraries. Thirdly most systems already have the X libraries in the linker search path anyway, wherever they may happen to be, so this is just included as a fallback "just in case". Do you have an example of a specific GNU/Linux distribution which fails to build spacenavd due to not adding the correct X library path to the linker search paths?
I'm on 64-bit Slackware 14.2, and the X11 libs are in /usr/lib64/. I also have 32-bit compatibility libraries installed (common, but not "stock" Slackware), and the X11 32-bit libs are in /usr/lib/. In addition, /usr/X11 is a symlink to X11R6/ and /usr/X11R6/lib64 is a symlink to ../lib64 (and /usr/X11R6/lib is a symlink to ../lib) so the current configure script that sets
xlib = -L/usr/X11/lib -lX11
in the Makefile causes the application to be linked against the 32-bit libX11.so instead of the 64-bit libX11.so. On my system:
$ pkg-config --libs --cflags x11
-lX11
So just removing "-L/usr/X11/lib" would cause it to work correctly for me.
With that being said, "best practice" on Slackware is to compile on a clean system rather that the currently in-use system. I have a clean 64-bit chroot that I normally use to compile software, and I just tried using it to compile spacenavd, and indeed it correctly links against /usr/lib64/libX11.so.6, because there are no libraries in /usr/lib/ (and thus /usr/X11/lib/) to link against.
So, on Slackware 64-bit with 32-bit libraries installed I have two options: 1) Remove "-L/usr/X11/lib" 2) Compile in a clean 64-bit chroot.
That's strange. The linker should look into /usr/X11/lib, see that libX11.so there is of a different architecture, and ignore it moving on to the next library directory. Could you post the build output when this problem happens? I'd like to see exactly what the linker complains about.
If it comes down to a choice, I'd rather just remove -L/usr/X11/lib than add a dependency to pkg-config. I'll have to go back to old commits and see if something forced me to add it in the first place, or if it was just a "just to be sure" thing.
This is the output when building on 64-bit Slackware with 32-bit compatibility libraries installed:
$ add_cflags="-fPIC" ./configure --prefix=/usr --build=x86_64-slackware-linux
fatal: Not a git repository (or any of the parent directories): .git
configuring spacenavd -
prefix: /usr
optimize for speed: yes
include debugging symbols: yes
x11 communication method: yes
use hotplug: yes
creating Makefile ...
creating config.h
Done. You can now type make (or gmake) to compile spacenavd.
$ make
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/cfgfile.c -o src/cfgfile.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/client.c -o src/client.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/dev.c -o src/dev.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/dev_serial.c -o src/dev_serial.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/dev_usb.c -o src/dev_usb.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/dev_usb_darwin.c -o src/dev_usb_darwin.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/dev_usb_linux.c -o src/dev_usb_linux.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/dummy_usb.c -o src/dummy_usb.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/event.c -o src/event.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/hotplug_darwin.c -o src/hotplug_darwin.o
src/hotplug_darwin.c:44:0: warning: ISO C forbids an empty translation unit [-Wpedantic]
#endif /* __APPLE__ && __MACH__ */
^
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/hotplug_linux.c -o src/hotplug_linux.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/kbemu.c -o src/kbemu.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/magellan/smag.c -o src/magellan/smag.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/magellan/smag_comm.c -o src/magellan/smag_comm.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/magellan/smag_detect.c -o src/magellan/smag_detect.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/magellan/smag_event.c -o src/magellan/smag_event.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/proto_unix.c -o src/proto_unix.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/proto_x11.c -o src/proto_x11.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/serial/sball.c -o src/serial/sball.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/serial/sballserial.c -o src/serial/sballserial.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/spnavd.c -o src/spnavd.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/spnavd_win32.c -o src/spnavd_win32.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/xdetect_freebsd.c -o src/xdetect_freebsd.o
gcc -pedantic -Wall -g -O2 -fno-strict-aliasing -I./src -I/usr/local/include -fPIC -c src/xdetect_linux.c -o src/xdetect_linux.o
gcc -o spacenavd src/cfgfile.o src/client.o src/dev.o src/dev_serial.o src/dev_usb.o src/dev_usb_darwin.o src/dev_usb_linux.o src/dummy_usb.o src/event.o src/hotplug_darwin.o src/hotplug_linux.o src/kbemu.o src/magellan/smag.o src/magellan/smag_comm.o src/magellan/smag_detect.o src/magellan/smag_event.o src/proto_unix.o src/proto_x11.o src/serial/sball.o src/serial/sballserial.o src/spnavd.o src/spnavd_win32.o src/xdetect_freebsd.o src/xdetect_linux.o -L/usr/local/lib -L/usr/X11/lib -lX11 -lXi
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible /usr/X11/lib/libX11.so when searching for -lX11
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible /usr/X11/lib/libXi.so when searching for -lXi
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible /usr/X11/lib/libgcc_s.so when searching for -lgcc_s
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible /usr/X11/lib/libc.so when searching for -lc
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible /usr/X11/lib/libc.a when searching for -lc
/usr/lib64/gcc/x86_64-slackware-linux/5.5.0/../../../../x86_64-slackware-linux/bin/ld: skipping incompatible /usr/X11/lib/libgcc_s.so when searching for -lgcc_s
... and now I realize after reading your last comment that those aren't error messages; they are informational messages. Previously I had assumed those were error messages and didn't even check if the binary was created successfully. But it appears that it is:
$ ldd spacenavd
linux-vdso.so.1 (0x00007ffc89917000)
libX11.so.6 => /usr/lib64/libX11.so.6 (0x00007fa8d3d1c000)
libXi.so.6 => /usr/lib64/libXi.so.6 (0x00007fa8d3b0c000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa8d3743000)
libxcb.so.1 => /usr/lib64/libxcb.so.1 (0x00007fa8d3524000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fa8d3320000)
libXext.so.6 => /usr/lib64/libXext.so.6 (0x00007fa8d310e000)
libXau.so.6 => /usr/lib64/libXau.so.6 (0x00007fa8d2f0b000)
libXdmcp.so.6 => /usr/lib64/libXdmcp.so.6 (0x00007fa8d2d06000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa8d4057000)
Sorry for the noise!
Yeah that was pretty much what I was expecting the linker to do. There's some merit to investigating this further to see if that explicit library path is in any way necessary and remove the linker noise from the output if not, but I'll leave it as is for now.
The location for X11 libraries was hard coded to /usr/X11/lib, which may be incorrect for some 64-bit installations (which use /usr/X11/lib64). Use pkg-config instead of hardcoding library path.
Also use pkg-config for Xi.