e06b
![]() |
|
|
|
|
|||||||
| Userland Programming & Scripting C, Shell, Perl, Sed & Awk |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
||||
|
||||
|
Hello, I am attempting to compile a simple C++ program that produces an Xlib window. Here is the program which is from a tutorial:
Code:
#include <X11/Xlib.h> // Every Xlib program must include this
#include <assert.h> // I include this to test return values the lazy way
#include <unistd.h> // So we got the profile for 10 seconds
#define NIL (0) // A name for the void pointer
main()
{
// Open the display
Display *dpy = XOpenDisplay(NIL);
assert(dpy);
// Get some colors
int blackColor = BlackPixel(dpy, DefaultScreen(dpy));
int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
// Create the window
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
200, 100, 0, blackColor, blackColor);
// We want to get MapNotify events
XSelectInput(dpy, w, StructureNotifyMask);
// "Map" the window (that is, make it appear on the screen)
XMapWindow(dpy, w);
// Create a "Graphics Context"
GC gc = XCreateGC(dpy, w, 0, NIL);
// Tell the GC we draw using the white color
XSetForeground(dpy, gc, whiteColor);
// Wait for the MapNotify event
for(;;) {
XEvent e;
XNextEvent(dpy, &e);
if (e.type == MapNotify)
break;
}
// Draw the line
XDrawLine(dpy, w, gc, 10, 60, 180, 20);
// Send the "DrawLine" request to the server
XFlush(dpy);
// Wait for 10 seconds
sleep(10);
}
Code:
wind.cpp:1:21: error: X11/Xlib.h: No such file or directory wind.cpp: In function 'int main()': wind.cpp:8: error: 'Display' was not declared in this scope wind.cpp:8: error: 'dpy' was not declared in this scope wind.cpp:8: error: 'XOpenDisplay' was not declared in this scope wind.cpp:11: error: 'DefaultScreen' was not declared in this scope wind.cpp:11: error: 'BlackPixel' was not declared in this scope wind.cpp:12: error: 'WhitePixel' was not declared in this scope wind.cpp:15: error: 'Window' was not declared in this scope wind.cpp:15: error: expected `;' before 'w' wind.cpp:18: error: 'w' was not declared in this scope wind.cpp:18: error: 'StructureNotifyMask' was not declared in this scope wind.cpp:18: error: 'XSelectInput' was not declared in this scope wind.cpp:21: error: 'XMapWindow' was not declared in this scope wind.cpp:24: error: 'GC' was not declared in this scope wind.cpp:24: error: expected `;' before 'gc' wind.cpp:25: error: 'gc' was not declared in this scope wind.cpp:25: error: 'XSetForeground' was not declared in this scope wind.cpp:29: error: 'XEvent' was not declared in this scope wind.cpp:29: error: expected `;' before 'e' wind.cpp:30: error: 'e' was not declared in this scope wind.cpp:30: error: 'XNextEvent' was not declared in this scope wind.cpp:31: error: 'MapNotify' was not declared in this scope wind.cpp:35: error: 'XDrawLine' was not declared in this scope wind.cpp:36: error: 'XFlush' was not declared in this scope Any ideas would be most welcome. Last edited by SirDice; August 8th, 2012 at 07:52. Reason: Read about formatting tags: http://forums.freebsd.org/misc.php?do=bbcode |
|
#2
|
||||
|
||||
|
Show us the complete command you used to compile this.
__________________
Senior UNIX Engineer at Unix Support Nederland Experience is something you don't get until just after you need it. |
|
#3
|
||||
|
||||
|
compile code:
$ g++ -o -window wind.cpp -lX11 -L/usr/X6R11/lib -I /usr/X6R11/include
|
|
#4
|
||||
|
||||
|
X6R11 doesn't exist. If anything it should be X11R6. But even that shouldn't exist anymore.
Use /usr/local/lib/ and /usr/local/include/.
__________________
Senior UNIX Engineer at Unix Support Nederland Experience is something you don't get until just after you need it. |
|
#5
|
||||
|
||||
|
Thanks, this compiles now. However,if I run the program from the console I get a segmentation fault (core dumped) error. Why is this?
|
|
#6
|
||||
|
||||
|
It's ok, I have solved my problem.
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shared memory and Linux program problem | cutter | FreeBSD Development | 3 | March 25th, 2012 09:27 |
| [Solved] Problem compiling php5-dba on 7.4 | gregober | Installation and Maintenance of FreeBSD Ports or Packages | 2 | February 13th, 2012 15:09 |
| [Solved] problem with C program | psycho | Userland Programming & Scripting | 3 | May 6th, 2010 14:02 |
| FreeBSD Program Compiling-Installing | ligregni | FreeBSD Development | 2 | March 8th, 2010 09:15 |
| [Solved] Problem with a linux program using java (on FreeBSD) | cell | Installation and Maintenance of FreeBSD Ports or Packages | 10 | July 25th, 2009 20:12 |