X11/Xlib.h: no such file or directory - MINIX 3 and X11, where to get headers?

1,531 views
Skip to first unread message

PolGraphic

unread,
Apr 19, 2012, 3:12:36 PM4/19/12
to minix3
Hello.
I have installed X11 and gcc on my MINIX 3:
# pkgin install x11
# pkgin install gcc44

I can start the x windows:
startx
And I see the 'graphics'.

Now I want to compile simple program with X11 on MINIX 3 using g++:
g++ main.cpp

But there are errors for included X11 files:
error: X11/Xlib.h: no such file or directory
error: X11/Xutil.h: no such file or directory

How can I get that headers (I used find to make sure I haven't them in
the other folders)?
And where to place them?

Maybe something with:
pkgin install Something?

I have found:
sudo apt-get install libx11-dev
But that was for ubuntu, similar command (pkgin install libx11-dev)
does not work.

pikpik

unread,
Apr 19, 2012, 7:11:35 PM4/19/12
to minix3
Hi

On Apr 19, 3:12 pm, PolGraphic wrote:

> I have found:
> sudo apt-get install libx11-dev
> But that was for ubuntu, similar command (pkgin install libx11-dev)
> does not work.

The package "x11-links" might be what you're looking for. Tip: "pkgin
search [package]" can help you find things.

I hope this helps,
pikpik

PolGraphic

unread,
Apr 19, 2012, 7:22:34 PM4/19/12
to minix3
Thanks about the pkgin seach option, I tried it for "pkgin search x11"
and installed all results one by one (x11-6.8.2 I had earlier, x11-
links-0.68 that you have mentioned, xpkgwedge-1.17 and
xproto-7.0.18).

Unfortunately, my headers weren't there ("find / Xlib.h" after
installing with no results).

Is there something more I can do?

pikpik

unread,
Apr 19, 2012, 9:39:03 PM4/19/12
to minix3
Hi,

On Apr 19, 7:22 pm, PolGraphic wrote:

> Unfortunately, my headers weren't there ("find / Xlib.h" after
> installing with no results).
>
> Is there something more I can do?

I think the "-name" parameter will help:

find / -name Xlib.h

It looks like both "x11" and "x11-links" install different copies of
Xlib.h. I don't know how they interact or if that will introduce any
problems though. (It hasn't been a problem in the past, I think.)

PolGraphic

unread,
Apr 20, 2012, 6:39:18 PM4/20/12
to minix3
Thanks.
Now I have another problem.
After typing:
g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main.cpp

I get errors:
undefined referende to 'XOpenDisplay'
undefined referende to 'XCreateSimpleWindow'
undefined referende to 'XSelectInput'
undefined referende to 'XMapWindow'
undefined referende to 'XNextEvent'
And few more.

I have added -L/usr/pkg/X11R6/lib -lX11 in g++, so why I get that
errors and how to solve them?

pikpik

unread,
Apr 20, 2012, 7:58:39 PM4/20/12
to minix3
Hi,

On Apr 20, 6:39 pm, PolGraphic wrote:

> Thanks.
> Now I have another problem.
> After typing:
> g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main.cpp
>
> I get errors:
> undefined referende to 'XOpenDisplay'
> undefined referende to 'XCreateSimpleWindow'
> undefined referende to 'XSelectInput'
> undefined referende to 'XMapWindow'
> undefined referende to 'XNextEvent'
> And few more.
>
> I have added  -L/usr/pkg/X11R6/lib -lX11 in g++, so why I get that
> errors and how to solve them?

Unfortunately, I don't know. One possibility is that libX11.a is
missing these symbols; I think this is the case for at least
XOpenDisplay. I think you can look inside the library and see its
symbols with "nm /usr/pkg/X11R6/lib/libX11.a."

Just wondering, but should "-I/usr/pkg/X11R6/include" also be used for
the includes path?

wolf python london

unread,
Apr 20, 2012, 10:31:18 PM4/20/12
to min...@googlegroups.com
On 21 April 2012 06:39, PolGraphic <polgr...@interia.pl> wrote:
> Thanks.
> Now I have another problem.
> After typing:
> g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main.cpp
>
> I get errors:
> undefined referende to 'XOpenDisplay'
> undefined referende to 'XCreateSimpleWindow'
> undefined referende to 'XSelectInput'
> undefined referende to 'XMapWindow'
> undefined referende to 'XNextEvent'
> And few more.
>
> I have added  -L/usr/pkg/X11R6/lib -lX11 in g++, so why I get that
> errors and how to solve them?
>
-lX11, it's the lowercase *L* , not the uppercase i. Are you sure of it ?

> On Apr 20, 3:39 am, pikpik <pikpik.1...@gmail.com> wrote:
>> Hi,
>>
>> On Apr 19, 7:22 pm, PolGraphic wrote:
>>
>> > Unfortunately, my headers weren't there ("find / Xlib.h" after
>> > installing with no results).
>>
>> > Is there something more I can do?
>>
>> I think the "-name" parameter will help:
>>
>> find / -name Xlib.h
>>
>> It looks like both "x11" and "x11-links" install different copies of
>> Xlib.h. I don't know how they interact or if that will introduce any
>> problems though. (It hasn't been a problem in the past, I think.)
>>
>> I hope this helps,
>> pikpik
>
> --
> You received this message because you are subscribed to the Google Groups "minix3" group.
> To post to this group, send email to min...@googlegroups.com.
> To unsubscribe from this group, send email to minix3+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/minix3?hl=en.
>

--
________________________
Yes, I use Debian GNU/L
wolf python london(WPL)
Do as you soul should do !
________________________

PolGraphic

unread,
Apr 21, 2012, 6:22:57 AM4/21/12
to minix3
I have tried 'nm /usr/pkg/X11R6/lib/libX11.a > res.txt' and then 'grep
-i "XOpenDisplay" ./res.txt' and got:
00000458 T XOpenDisplay
U XOpenDisplay

So now I think there is XOpenDisplay in libX11.a. So why I get
"undefined reference"?

My command is:
g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main2.cpp

Where -lX11 is lower-case L and -I/usr/pkg/X11R6/include is upper-case
i.
I have tried with changing lower-case L to upper-case i and vice versa
but without a good result.

wolf python london

unread,
Apr 21, 2012, 11:21:30 AM4/21/12
to min...@googlegroups.com
On 21 April 2012 18:22, PolGraphic <polgr...@interia.pl> wrote:
> I have tried 'nm /usr/pkg/X11R6/lib/libX11.a > res.txt' and then 'grep
> -i "XOpenDisplay" ./res.txt' and got:
> 00000458 T XOpenDisplay
>               U XOpenDisplay
>
> So now I think there is XOpenDisplay in libX11.a. So why I get
> "undefined reference"?
>
I'm not sure: it may be the problem of combination programming of c and c++.
It seems that c++ use a different symbol in object file.
My advice is:
1)use gcc to compile it and better change the source file extension
(I mean .c). Or
2) use extern "C" in the cpp source file and use g++ to compile it
If two ways doesn't help, plz attach your main.cpp , let's see how to
fix it together :-)


> My command is:
> g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main2.cpp
>
> Where -lX11 is lower-case L and -I/usr/pkg/X11R6/include is upper-case
> i.

L/usr/pkg/X11R6 --- L to tell compiler(Gcc here) to look the library
to link in this dirs;
-l/X11 --- l to tell compiler to link the libX11.a library
-I/usr/pkg/X11R6 -- I to tell compiler look the header file in this dir

PolGraphic

unread,
Apr 21, 2012, 3:47:00 PM4/21/12
to minix3
If there is an option, I want to use C++ not just C (I want to use
elements from C++ that aren't in C).

I have tried:
g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main3.cpp

For mai3.cpp with extern "C" as you mentioned (I hope I done it
right):

extern "C"{
#include <X11/Xlib.h>
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
Display *d;
Window w;
XEvent e;
char *msg = "Hello, World!";
int s;

d = XOpenDisplay(NULL);
if (d == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}

s = DefaultScreen(d);
w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 100, 100, 1,
BlackPixel(d, s), WhitePixel(d, s));
XSelectInput(d, w, ExposureMask | KeyPressMask);
XMapWindow(d, w);

while (1) {
XNextEvent(d, &e);
if (e.type == Expose) {
XFillRectangle(d, w, DefaultGC(d, s), 20, 20, 10, 10);
XDrawString(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg));
}
if (e.type == KeyPress)
break;
}

XCloseDisplay(d);
return 0;
}

I got the same errors about undefined reference to XOpenDisplay and
others.

What was strange for me, the gcc gave me the same errors now:
g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main3.cpp

On Apr 21, 5:21 pm, wolf python london <lyh19901...@gmail.com> wrote:
> On 21 April 2012 18:22, PolGraphic <polgrap...@interia.pl> wrote:> I have tried 'nm /usr/pkg/X11R6/lib/libX11.a > res.txt' and then 'grep

wolf python london

unread,
Apr 21, 2012, 10:25:11 PM4/21/12
to min...@googlegroups.com
I test it in the vbox with latest minix3 installed. I have x11
xproto,gcc44, pkg-config installed (using pkgin ),
It builds fine(though X doesn't work in vbox).

You can also try pkg-config and upgrade all your packages to latest.

$g++ -o main3 main3.cpp `pkg-config --cflags --libs x11`

Here is the screenshot(http://picpaste.com/test-uZrWS14H.png)


> On Apr 21, 5:21 pm, wolf python london <lyh19901...@gmail.com> wrote:
>> On 21 April 2012 18:22, PolGraphic <polgrap...@interia.pl> wrote:> I have tried 'nm /usr/pkg/X11R6/lib/libX11.a > res.txt' and then 'grep
>> > -i "XOpenDisplay" ./res.txt' and got:
>> > 00000458 T XOpenDisplay
>> >               U XOpenDisplay
>>
>> > So now I think there is XOpenDisplay in libX11.a. So why I get
>> > "undefined reference"?
>>
>> I'm not sure: it may be the problem of combination programming of c and c++.
>> It seems that c++ use a different symbol in object file.
>> My advice is:
>> 1)use gcc to compile it  and better change the source file extension
>> (I mean  .c).  Or
>> 2) use extern "C"  in the cpp source file and use g++ to compile it
>> If two ways doesn't help, plz attach your main.cpp , let's see how to
>> fix it together :-)
>>
>> > My command is:
>> > g++ -L/usr/pkg/X11R6/lib -lX11 -I/usr/pkg/X11R6/include main2.cpp
>>
>> > Where -lX11 is lower-case L and -I/usr/pkg/X11R6/include is upper-case
>> > i.
>>
>> L/usr/pkg/X11R6  --- L to tell compiler(Gcc here)  to look the library
>> to link in this dirs;
>> -l/X11  --- l to tell compiler to link  the libX11.a library
>> -I/usr/pkg/X11R6  -- I to tell compiler look the header file in this dir
>

PolGraphic

unread,
Apr 22, 2012, 8:24:43 AM4/22/12
to minix3
Thanks!
I compiled it with your command and pkg-config (I forgot to install it
earlier...).
:-)

However, After I set
chmod +x ./main3
and run ./main3 I got "Cannot open display" from my program (so the
XOpenDisplay(NULL) returned NULL). I don't know how to solve it. I
found few tips, tried "xhost +localhost" but got "xhost: unable to
open display "" ", also export DISPLAY=:0.0 (after that effect was the
same, but I was waiting a little bit longer for error to show).

It's looks a little like never-ending story, but I really thank you
for help, I feel that I am much closer to the happy end.

On Apr 22, 4:25 am, wolf python london <lyh19901...@gmail.com> wrote:
> > For more options, visit this group athttp://groups.google.com/group/minix3?hl=en.

wolf python london

unread,
Apr 22, 2012, 9:10:07 AM4/22/12
to min...@googlegroups.com
On 22 April 2012 20:24, PolGraphic <polgr...@interia.pl> wrote:
> Thanks!
> I compiled it with your command and pkg-config (I forgot to install it
> earlier...).
> :-)
>
> However,  After I set
> chmod +x ./main3
The executable file (here main3) is already executable , so there is no need to
take this step.

> and run ./main3 I got "Cannot open display" from my program (so the
> XOpenDisplay(NULL) returned NULL). I don't know how to solve it. I
> found few tips, tried "xhost +localhost" but got "xhost: unable to
> open display "" ", also export DISPLAY=:0.0 (after that effect was the
> same, but I was waiting a little bit longer for error to show).
>
Are you in X?
According to the manual of X:
****************
SYNTAX
Display *XOpenDisplay(char *display_name);

int XCloseDisplay(Display *display);

ARGUMENTS
display Specifies the connection to the X server.

display_name
Specifies the hardware display name, which determines the
display and communications domain to be used. On a POSIX-
conformant system, if the display_name is NULL, it defaults
to the value of the DISPLAY environment variable.
********************
XOpenDisplay with a NULL parameter should return the pointer to a
Display structure which is the value of
the DISPLAY environment variable. So set the variable manually may not
work. I have little experience in
xlib programming . It's just a simply analysis.

BTW, this tiny code builds and works in NetBSD and Debian.

> For more options, visit this group at http://groups.google.com/group/minix3?hl=en.

PolGraphic

unread,
Apr 22, 2012, 11:30:39 AM4/22/12
to minix3
You're right. Now everything works perfectly :-)

luispa...@gmail.com

unread,
Mar 27, 2018, 3:04:51 PM3/27/18
to minix3
Hi, I know it's almost 6 years later, but I still get "Cannot open display" when I run "./main3". I'm using MINIX 3.4

Do you remember how you fixed this?

luispa...@gmail.com

unread,
Mar 27, 2018, 5:43:50 PM3/27/18
to minix3
I got it to work, but twm must be running after using startx
Reply all
Reply to author
Forward
0 new messages