www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/15/09:08:40

Date: Wed, 15 Apr 1998 16:06:37 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Jason <dygron AT ace-net DOT com DOT au>
cc: djgpp AT delorie DOT com
Subject: Re: Compiling C and C++ in same project
In-Reply-To: <01bd6822$b737b4e0$99a325cb@jring>
Message-ID: <Pine.SUN.3.91.980415160317.10047C-100000@is>
MIME-Version: 1.0

On 15 Apr 1998, Jason wrote:

> 	I have written some code in C++ and would like to add prewritten code and
> object files which were written in C.  Unfortunately, when the linker gets
> hold of the object files compiled under C to be linked with the object file
> compiled unter C++, I get errors saying that the functions defined in the C
> modules do not exist (but they really do!).

You need to tell the C++ compilers these functions are in C.  The usual 
way to do this is to include ``extern "C"'' in their prototypes, like 
this:

#ifdef __cplusplus
extern "C" {
#endif

  /* put the usual C-style prototypes here */

#ifdef __cplusplus
}
#endif

> (Also, could someone explain what the difference between
> object files produced by a C compiler, and object files produced by a C++
> compiler?).

There is no difference.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019