[comp.windows.x] Using C++ and X together

bourd@buster.cps.msu.edu (Robert Bourdeau) (02/19/91)

Is anyone aware of problems using the X Toolkit and Xw with g++?

I have been trying to compile a C++ program which incorporates X window
stuff. I can't get past the compilation.  Everything compiles fine until
I add the X interface. When the X stuff was added, I started getting things
like type conflicts, and even parse errors in the X header files.

When I use standard C and X, there is no problem. So it seems that there is
some strange incompatibility between C++ and X.  (Unless of course you want
to use Interviews which I don't).

Does anyone have ideas or similar experience?

Thanks for any information.

--- Robert Bourdeau
--- bourd@buster.cps.msu.edu
--- Michigan State University

cjmchale@cs.tcd.ie (Ciaran McHale) (02/20/91)

In <1991Feb19.153737.11179@msuinfo.cl.msu.edu>
bourd@buster.cps.msu.edu (Robert Bourdeau) writes:

>[compilation problems using Xt and C++]

This ought to be in the FAQ.

The C++ support in the X header files is buggy in the virgin
X11R4 release which causes compilation problems. The problem
will go away if you apply some of the patches to your X
setup. (I *think* you need up to patch level 12.) See the
FAQ posting for details on how to obtain patches for X.


Ciaran.
-- 
Ciaran McHale		"Verbosity says it all"			      ____
Department of Computer Science, Trinity College, Dublin 2, Ireland.   \  /
Telephone: +353-1-772941 ext 1538	FAX: +353-1-772204	       \/
Telex: 93782 TCD EI			email: cjmchale@cs.tcd.ie

gwu@nujoizey.tcs.com (George Wu) (02/20/91)

In article <1991Feb19.153737.11179@msuinfo.cl.msu.edu>,
bourd@buster.cps.msu.edu (Robert Bourdeau) writes:
|> Is anyone aware of problems using the X Toolkit and Xw with g++?
|> 
|> I have been trying to compile a C++ program which incorporates X window
|> stuff. I can't get past the compilation.  Everything compiles fine until
|> I add the X interface. When the X stuff was added, I started getting things
|> like type conflicts, and even parse errors in the X header files.

     I presume you are using X11, Release 3.  You problem arises because you
are calling C functions from C++.  You need to envelop all #include
statements of X header files within an extern "C" statement.  This will
solve the prototype errors.  Note this works only for g++, not other C++
compilers, because g++ does not check function prototypes within an extern
"C" statement.

     There are a few places where the C++ keyword "class" is used in the X
header files.  This error can be corrected by using another name for the
class field.

							George

----
George J Wu, Software Engineer        | gwu@tcs.com or uunet!tcs!gwu
Teknekron Communications Systems, Inc.| (415) 649-3752
2121 Allston Way, Berkeley, CA, 94704 | Quit reading news.  Get back to work.

rfg@NCD.COM (Ron Guilmette) (03/02/91)

In article <1991Feb19.202436.19754@cs.tcd.ie> cjmchale@cs.tcd.ie (Ciaran McHale) writes:
>
>The C++ support in the X header files is buggy in the virgin
>X11R4 release which causes compilation problems. The problem
>will go away if you apply some of the patches to your X
>setup. (I *think* you need up to patch level 12.) See the
>FAQ posting for details on how to obtain patches for X.

Another possible approach woul be to use protoize to protoize *all* of the
X11 sources.  I do not know anyone who has been brave enough to try this
yet though.

-- 

// Ron Guilmette  -  C++ Entomologist
// Internet: rfg@ncd.com      uucp: ...uunet!lupine!rfg
// Motto:  If it sticks, force it.  If it breaks, it needed replacing anyway.