Thanks to everyone who replied to my email.  It turned out that the problem was in X_application.H.  The full file was:

 

#ifndef X_H

#define X_H

#include <Xm/Xm.h>

class X_application

{

public:

  X_application(void);

  ~X_application(void);

};

#endif


It turned out that X_H was already used by another X include file.  By changing the #ifndef wrapper to #ifndef X_app_H, the problem was solved. 8-)

 

Thanks heaps to James Boyden who figured this one out off-list. 8-)

 

thanks guys

 

David Buddrige.  8-)
--__--__--

To: [EMAIL PROTECTED]
From: [EMAIL PROTECTED]
Date: Mon, 29 Oct 2001 17:57:16 +0800
Subject: [Xpert]Programming an X app using C++

Hi all,


This is a re-posting of a question I sent a few weeks back.  Since then
I've
been flat out with project work, and so hadn't gotten back to the problem.
Anyway, there was a typo in my email, which lead people to suspect that it
was an error with my destructor definition; however this was a problem in
the
email not the actual code.  Anyway, my apologies for the typo and
subsequent
confusion.

What I am trying to figure out is how to develop an X application
using C++.  I am using g++ version 2.96 as my compiler.  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