Hi all,

I am currently teaching myself to program X app's.  I am using a
workstation running Redhat 7.0 using XFree86 version 4.0.1.

My normal work requires me to program in C++, so I got a hold of a
web-tutorial for X coding
(http://www.comp.lancs.ac.uk/computing/users/sean/Motif-Workshop/workshop1.html),

and, based on the information therein, started to write a simple class.

To start off with, I thought I'd  write a class called "X_application" to
encapsulate all of the X initialisation code, so that subsequently I can
just inherit from the class whenever I want to put an X app together.

I wrote the following code in 3 files (X_application.H, X_application.C and
main.C) :

X_application.H:

class X_application
{
public:
  X_application();
  X_application();
};

X_application.C:

#include "X_application.H"

X_application::X_application()
{
}

X_application::~X_application()
{
}

main.C:

#include "X_application.H"

int main(int argc, char **argv)
{
  X_application x_app;
}


...
This compiles fine.

I then added the following code to X_application.C

#include <Xm/Xm.h>

such that X_application.C now looked like this:


#include "X_application.H"
#include <Xm/Xm.h>

X_application::X_application()
{
}

X_application::~X_application()
{
}


and then tried to compile.  This resulted in a stream of errors, apparently
from /usr/include/X11/Xlib.h, of the form:

/usr/include/X11/Xlib.h:211: syntax error before `:'

After discussion with a collegue, I swapped the
#include "X_application.H"

and

#include <Xm/Xm.h>

So that <Xm/Xm.h> came first.

A fresh compile lead to two errors:

X_application.C:4: syntax error before `::'
X_application.C:8: syntax error before `::'


This lead me to suspect that there was a problem relating to using C and
C++ headers together, so I wrapped the #include <Xm/Xm.h> such that
X_application.C now looked like this:

extern "C"
{
#include <Xm/Xm.h>
}
#include "X_application.H"

X_application::X_application()
{
}

X_application::~X_application()
{
}


A re-compile of this code however produced exactly the same errors.

My next step was to get onto Google.com and do a search for "Xm.h
" and "g++".  The results of this indicated to me that there is a known
problem with the X headers that make it complain when it comes across C++
code.

My question:

Is there any way around this?  Based on a few usenet posts that I came
across, I have tried compile flags such as:

-fpermissive

and

-fhonor-std

to no avail.  Short of writing all the X code in straight C in a seperate
file and then extern "C" ing each of the functions (which strikes me as
ugly and a real pain),  I am not sure how else to proceed.  Is there some
workaround for this short of the pure C option?

thanks heaps

David Buddrige
Software Engineer
Logica

_______________________________________________
Xpert mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/xpert

Reply via email to