This is the mail archive of the crossgcc@sourceware.cygnus.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more infromation.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Problem with project contained mixed C and C++ sources


On Thu, 16 Sep 1999, Jurgis Armanavichius wrote:

> I have problem with project contained mixed C and C++ sources.
> My environment is GCC (based on egcs-1.1.2) for H8/300H CPU.
> Some modules of my project are traditional C program modules,
> and some is C++. For example, I have simple class for CRC-8
> calculating. To using it in another modules I wrote very simple
> user interface functions:
> void CRC_init(void);
> void CRC_byte(byte byt);  and so on.
> 
> Problem is: then I compile this module I have function names
> like this (in generated ASM listing):
> 
>     .global    _CRC_init__Fv
>     .global    _CRC_byte__FUc
> 
> And, of course, link procedure fails.
> 
> How to solve this problem? Thank you.

What you are seeing are C++ mangled names.  They can be
turned off by using C linkage.  That can be done by
wrapping the declarations inside an extern "C" directive.
The best way is to do that is to put the directive in the
header file, and enable it for C++ modules only.  The C++
compiler will defile __cplusplus if & only if it is
compiling a C++ module, so one to do that is as follows:

#ifdef  __cplusplus
extern "C" {
#endif

typedef unsigned char byte;

void CRC_init(void);
void CRC_byte(byte byt);

#ifdef  __cplusplus
}
#endif

This should be done for anything that you wish to use in both C and C++
programs (whether defined in a C or C++ program).

> Jurgis Armanavichius
> Firma MEDELKOM, http://www.medelkom.com

Mike
--
C. M. Heard/VVNET, Inc.
heard@vvnet.com


------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]