Home > Software engineering >  Problems finding X11 libraries trying to build another program on Mac
Problems finding X11 libraries trying to build another program on Mac

Time:04-29

In the process of trying to build some software AVL I'm getting some X11 library issues. I've done this install a few years ago and remember it being straight forward, but it was on an older version of OS el capitan I think and I'm on a "lite" version of Big Sur. I installed XQuartz and I can see the files it's expecting, but it seems to have trouble with the path to X11 per my understanding of this error

In file included from xwin11/Xwin2.c:74:
/usr/X11/include/X11/Xlib.h:44:10: fatal error: 'X11/X.h' file not found

In order for it to find Xlib.h I modified this (which I'm pretty sure isn't correct) from

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>  

to

#include </usr/X11/include/X11/Xlib.h>
#include </usr/X11/include/X11/Xutil.h>
#include </usr/X11/include/X11/cursorfont.h>

Before it would die on finding Xlib.h. It also seems to be ignoring the linking line I gave it in the config.make file

LINKLIB = -I/usr/X11/include -L/usr/X11/lib -lX11

Is there an environment variable or path I'm missing in my profile? Is it ignoring the linking flag. Or did I set this up incorrectly in the config file? What's really odd is that now it's finding Xlib.h but it can't find X.h and they live in the same folder, which really makes me think it just doesn't know where to find the X11 "stuff" .

Thanks!

CodePudding user response:

Here's how to solve it:

  • determine from the compiler messages what include files the compiler cannot find
  • find them yourself
  • tell the compiler where they are
  • repeat above steps for libraries it cannot link

So, it cannot find Xlib.h. Let's find that:

find / -name Xlib.h 2>/dev/null

and, on my machine, I find:

/opt/X11/include/X11/Xlib.h

So that means I need to tell the compiler where to look for header files like this:

g   -I /opt/X11/include ...

Then, when it encounters this in your code:

#include <X11/Xlib.h>

that means it will actually be expecting to find:

/opt/X11/include/X11/Xlib.h

Now, let's do the libraries:

find / -name libX11.dylib 2> /dev/null

and, on my machine, I find:

/opt/X11/lib/libX11.dylib

so that means I need:

g   -I /opt/X11/include -L /opt/X11/lib/ ...

CodePudding user response:

Thanks @MadScientist your comment was the key. I moved the

-I/usr/X11/include

out of the linking flag and into the compile flag and that solved it!

  • Related