# Ruby and Borland C++

**URL:** <https://www.ruby-forum.com/t/ruby-and-borland-c/69547>\
**Category:** Ruby\
**Created:** [September 21, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/ruby-and-borland-c/69547 "2006-09-21T18:26:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Sig](https://www.ruby-forum.com/u/Sig)\
**Post date:** [September 21, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/ruby-and-borland-c/69547/1 "2006-09-21T18:26:34Z")

</div>

Hello all,

I successfully build ruby using both Borland C++ Builder 6 and BDS2006  
C++. However when I try to include ruby.h in my C++ project I get  
compiler errors:

[C++ Error] stdio.h(384): E2167 ‘\_strerror(const char \*)’ was previously  
declared with the language ‘C’  
[C++ Error] stdio.h(391): E2167 ‘\_wperror(const wchar\_t \*)’ was  
previously declared with the language ‘C’  
[C++ Error] stdio.h(430): E2167 ‘perror(const char \*)’ was previously  
declared with the language ‘C’  
[C++ Error] stdio.h(447): E2167 ‘strerror(int)’ was previously declared  
with the language ‘C’  
…

The debugger jumps into stdio.h file and stops at the line:  
using std::\_strerror;

If I create pure C project it works just fine. Any ideas how can I get  
it work under C++ project? I’ve tried to figure out what causes the  
error and looks like it’s coming from win32.h where stdio.h functions  
are redeclared.

---

<div class="post-metadata">

**Author:** ![Sig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Sig](https://www.ruby-forum.com/u/Sig)\
**Post date:** [September 21, 2006, 6:56pm UTC](https://www.ruby-forum.com/t/ruby-and-borland-c/69547/2 "2006-09-21T18:56:42Z")

</div>

Sig wrote:

/ …

> If I create pure C project it works just fine. Any ideas how can I get  
> it work under C++ project? I’ve tried to figure out what causes the  
> error and looks like it’s coming from win32.h where stdio.h functions  
> are redeclared.

Just based on what you have posted, you need to wrap the ruby.h header  
content the same way the C and C++ headers are wrapped.

To avoid double-reading, a typical header file will look like this:

#ifndef UNIQUE\_HEADER\_NAME  
#define UNIQUE\_HEADER\_NAME

# header content goes here

#endif

This arrangement prevents multiple reads of the same header file.

According to the error messages, it seems that the ruby.h file contains  
content already read and defined in other header files. One solution is  
to  
borrow the special defined name from a conflicting header file, and say:

#ifndef UNIQUE\_HEADER\_NAME  
#define UNIQUE\_HEADER\_NAME  
#include ruby.h  
#endif

This may be too simple a solution, but it is reasonably clear that a  
classic  
C/C++ multiple-header-read is happening. You may have to work out a more  
complex solution than this example.

---

<div class="post-metadata">

**Author:** ![Sig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Sig](https://www.ruby-forum.com/u/Sig)\
**Post date:** [September 21, 2006, 7:36pm UTC](https://www.ruby-forum.com/t/ruby-and-borland-c/69547/3 "2006-09-21T19:36:52Z")

</div>

Paul L. wrote:

> content the same way the C and C++ headers are wrapped.  
> This arrangement prevents multiple reads of the same header file.  
> This may be too simple a solution, but it is reasonably clear that a classic  
> C/C++ multiple-header-read is happening. You may have to work out a more  
> complex solution than this example.

Thanks Paul for you reply, still I can not solve the problem. I think  
this part from win32.h causes the error:

#if defined(\_\_cplusplus)  
extern “C++” {  
#endif

#include \<stdio.h\>  
#include \<stdlib.h\>  
#include \<string.h\>  
#include \<direct.h\>  
#include \<process.h\>  
#include \<time.h\>  
#include \<math.h\>  
#include \<signal.h\>  
#include \<sys/stat.h\>  
#include \<sys/types.h\>  
#ifdef HAVE\_SYS\_UTIME\_H

# include \<sys/utime.h\>

#else

# include \<utime.h\>

#endif  
#include \<io.h\>  
#include \<malloc.h\>

#if defined(\_\_cplusplus)  
}  
#endif

Looks like the same headers are defined twice as C++ and as C. Any other  
suggestions how to fix that? If I try to redefine them as C I get errors  
that types defined in stdio.h don’t exist.

---

<div class="post-metadata">

**Author:** ![Sig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Sig](https://www.ruby-forum.com/u/Sig)\
**Post date:** [September 22, 2006, 3:51pm UTC](https://www.ruby-forum.com/t/ruby-and-borland-c/69547/4 "2006-09-22T15:51:19Z")

</div>

On Fri, Sep 22, 2006 at 02:35:09AM +0900, Sig wrote:

> Thanks Paul for you reply, still I can not solve the problem. I think  
> this part from win32.h causes the error:
> 
> #if defined(\_\_cplusplus)  
> extern “C++” {  
> #endif

[snip some includes]

> #if defined(\_\_cplusplus)  
> }  
> #endif
> 
> Looks like the same headers are defined twice as C++ and as C. Any other  
> suggestions how to fix that? If I try to redefine them as C I get errors  
> that types defined in stdio.h don’t exist.  
> Hmmm, I’ve never seen extern “C++” before. That whole file looks very MS  
> compiler specific. I would suggest maybe trying to change it to extern  
> “C”. Of course that’s just a W.A.G.

---

<div class="post-metadata">

**Author:** ![Sig](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c4cdca/32.png) [@Sig](https://www.ruby-forum.com/u/Sig)\
**Post date:** [September 22, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/ruby-and-borland-c/69547/5 "2006-09-22T18:27:48Z")

</div>

Logan C. wrote:

> > }  
> > #endif
> > 
> > Looks like the same headers are defined twice as C++ and as C. Any other  
> > suggestions how to fix that? If I try to redefine them as C I get errors  
> > that types defined in stdio.h don’t exist.  
> > Hmmm, I’ve never seen extern “C++” before. That whole file looks very MS  
> > compiler specific. I would suggest maybe trying to change it to extern  
> > “C”. Of course that’s just a W.A.G.

Unfortunately it doesn’t help. I just got lost in these redefinitions.

Anyone has a success trying to use ruby with BCB?

Everything compiles just perfectly with MS C++. The problem is we have a  
big application written in BCB and now we have to extend it with  
scripting. Ruby seems to be a very good choice for that but we ran into  
BCB compatibility problems.
