I’ve been recently trying to work out why jhbuild fails to build xorg on my FreeBSD box. Traditionally I compile to /usr/local/ however after wanting to experiment with MPX I’ve set things up so that I compile to /usr/local/MPX
Sadly this kept breaking in xorg/lib/libX11 with the error:
xcb_io.c: In function 'require_socket': xcb_io.c:35: warning: implicit declaration of function 'xcb_take_socket' xcb_io.c:35: warning: nested extern declaration of 'xcb_take_socket' xcb_io.c: In function 'process_responses': xcb_io.c:188: error: 'GenericEvent' undeclared (first use in this function) xcb_io.c:188: error: (Each undeclared identifier is reported only once xcb_io.c:188: error: for each function it appears in.) xcb_io.c:189: error: 'xcb_ge_event_t' undeclared (first use in this function) xcb_io.c:189: error: expected expression before ')' token xcb_io.c:193: error: expected expression before ')' token xcb_io.c: In function '_XSend': xcb_io.c:332: warning: implicit declaration of function 'xcb_writev' xcb_io.c:332: warning: nested extern declaration of 'xcb_writev'
For the life of me I couldn’t make sense of it. GenericEvent is defined in xcb/xcb.h and checking the preprocessor output xcb.h was being included. Likewise the lack of xcb_ge_event_t was baffling me as it was certain in xcb/xcb.h. It wasn’t till I looked a little closer that I realised that the wrong xcb.h was being used. Turns out that /usr/local/include/xcb/xcb.h was being used however I wanted /usr/local/MPX/include/xcb/xcb.h to be used. Hence I tried adding -I/usr/local/MPX to CFLAGS with no success and also tried setting CC=”gcc -I/usr/local/MPX” also with no success. It just didn’t make sense!
Looking at the gcc line, /usr/local/MPX should have been used first. It wasn’t until I finally check the preprocessor what it thought the system paths were did it all make sense.
The output from cpp is below:
Using built-in specs.
Target: amd64-undermydesk-freebsd
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070719 [FreeBSD]
/usr/libexec/cc1 -E -quiet -v -I. -I../include/X11 -I../include -I../include/X11
-I../include -I../include/X11 -I../src/xcms -I../src/xkb -I../src/xlibi18n -I/usr/local/include
-D_LONGLONG -DHAVE_CONFIG_H -D_BSD_SOURCE -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT -D_THREAD_SAFE -D_BSD_SOURCE
-DX11_t -DTRANS_CLIENT -isystem /usr/local/MPX/include xcb_io.c -o xcb_io.lo -Wall -Wpointer-arith
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -fno-strict-aliasing -fworking-directory -O0
ignoring duplicate directory "/usr/local/MPX/include" ignoring duplicate directory "/usr/include" ignoring duplicate directory "../include/X11" ignoring duplicate directory "../include" ignoring duplicate directory "../include/X11" #include "..." search starts here: #include <...> search starts here: . ../include/X11 ../include ../src/xcms ../src/xkb ../src/xlibi18n /usr/local/include /usr/local/MPX/include /usr/include End of search list.
It turns out that jhbuild sets the environment variable C_INCLUDE_PATH, in this case to /usr/local/MPX/include. This variable adds a library to the system search path. Whilst it prepends to the system search path, -I options prepend the system search path, hence with one -I option being /usr/local/include, we get the ordering incorrect and the wrong header is used.
So now it was up to working out why /usr/local/include was needed. Searching config.log it turns out the bigfontproto was needed by libX11, pkg_config was searching for it and finding it not in /usr/local/MPX/lib/share/pkg_config but in /usr/local/lib/share/pkg_config. The reason for this is bigfontproto wasn’t listed as a dependancy in the xorg.modules file used by jhbuild (avaliable at:http://cgit.freedesktop.org/xorg/util/modular/tree/xorg.modules). Because of this bigfont proto wasn’t being built by jhbuild. Hence the only bigfontproto that existed on the box was the default system bigfont proto which WAS located under /usr/local/include.
The fix was simple. List xf86bigfontproto as a dependency in xorg.modules and all was good. bigfontproto is now pulled in as a dependency and hence gets built before libX11. pkg_config now correctly finds bigfontproto in /usr/local/MPX/lib/share/pkg_config hence doesn’t need to fallback to the system version so -I/usr/local/include doesn’t get added to the gcc line. Hence the compiler uses /usr/local/MPX/include/xcb/xcb.h rather than the one in /usr/local/include/xcb/xcb.h and the compiler errors vanish.
So now things are building and I’m off for a coffee!
(xorg.modules has also been correctly updated so some other poor person doesn’t have the same issues).