daniel@osf.org (Daniel Dardailler) (03/29/91)
Sure you can (even using Motif :-). You just have to be sure you are using the last updated R4 version of Xlib and Xt (patches ??), the original R4 had some problems with this stuff. The C functions in the libraries are handled by the extern "C" linkage clause, available in C++ and implemented in X since R4. -- Daniel Dardailler | OSF/Motif Team Open Software Foundation | Email : daniel@osf.org 11 Cambridge Center | Phone : (617) 621 8840 CAMBRIDGE, MA 02142 | Fax : (617) 621 0584
don@zardoz.coral.COM (Don Dewar) (03/30/91)
) Return-Path: <uunet!expo.lcs.mit.edu!xpert-mailer> ) Date: 29 Mar 91 06:27:37 GMT ) From: uunet!chpc.utexas.edu!xxvb746 (Yanling Qi (UT CHPC)) ) Organization: The University of Texas System - CHPC ) Subject: Can I build X application with g++? ) Newsgroups: comp.windows.x ) References: <1991Feb28.010627.895@lta.com> ) Sender: uunet!expo.lcs.mit.edu!xpert-request ) To: xpert@expo.lcs.mit.edu ) ) Hello friend, ) ) I have a project needed to be implemented in X with g++. I do not know ) if one can build X application with g++. I copyed the "puzzle source code" ) from the subdirectory X11 from my system to my directory and got my makefile ) by using "cmkmf". I compiled them successfully then I modified the makefile ) by changing CC = gcc ( original is CC = cc) and recompiled them successfully ) too. I got hundreds error when I changed CC =g++ and recompiled the codes. ) ) My questions were: ) (1) Can one biuld X application with g++? Yes, you can build X applications with g++. The problem you ran into is a problem with C++ in general. ) (2) if((#1) == yes) how should I deal with my c functions? As you may already know, most C++ compilers use a name munging scheme to differentiated overloaded functions. What you have to do when calling "C" functions is tell the C++ compiler not to do that. So you must declare the function using the following syntax. extern "C" { void cfunction1(char *, int); void cfunction2(char *, int); }; or extern "C" void cfunction1(char *, int); The function name, arguments and return value are at the programmers discretion of course. This syntax is know as the linkage section or linkage specfication. There is reference to it in the cfront 2.0 language spec and the C++ Annotated Reference Manual. I hope this is the problem you were referring to. I believe that ULowell has a set of X includes that are C++ compatible. What we usually do when we include X headers is this. extern "C" { #include <X11/Intrinsic.h> } ) ) Thank you! ) ) ) ----yanling ) ) +---------+ | Coral | |@@@@@*@**| |@@*@@**@@| Don Dewar |*@@**@@@@| Coral Network Corporation, Marlborough, MA |@***@@@@@| Internet: don@coral.com |@@**@@@@@| Phone: (508) 460-6010 |*********| Fax: (508) 481-6258 |Networks | +---------+