# Same compiler needed for C libraries?

**URL:** <https://www.ruby-forum.com/t/same-compiler-needed-for-c-libraries/81698>\
**Category:** Ruby\
**Created:** [January 11, 2007, 1:48pm UTC](https://www.ruby-forum.com/t/same-compiler-needed-for-c-libraries/81698 "2007-01-11T13:48:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [January 11, 2007, 1:48pm UTC](https://www.ruby-forum.com/t/same-compiler-needed-for-c-libraries/81698/1 "2007-01-11T13:48:23Z")

</div>

I’ve often heard that the same compiler should be used to compile  
Ruby and C extensions. I’ve also heard the same restriction for Perl,  
mod\_perl, and Apache. Libraries distributed as binaries for Windows  
have to be compiled with Microsoft the compiler as well, right?

Say, for example, you’ve got a Ruby in Solaris compiled with the Sun  
compiler, and the suite is not installed, nor can you install it.  
Would you try to tweak Makefiles to compile some library with gcc? Or  
is that just a bad idea and it is better to compile Ruby by hand  
bypassing the system Ruby and go on from there?

I am not very familiar with compilers and linkers, which is the  
reason behind these constraints?

– fxn

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [January 11, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/same-compiler-needed-for-c-libraries/81698/2 "2007-01-11T15:21:04Z")

</div>

Hi,

At Thu, 11 Jan 2007 21:47:47 +0900,  
Xavier N. wrote in [ruby-talk:233538]:

> I’ve often heard that the same compiler should be used to compile  
> Ruby and C extensions. I’ve also heard the same restriction for Perl,  
> mod\_perl, and Apache. Libraries distributed as binaries for Windows  
> have to be compiled with Microsoft the compiler as well, right?

It is not accurate. They have to be compiled with _same  
version_ of Microsoft compiler, or mingw and VC6.

> Say, for example, you’ve got a Ruby in Solaris compiled with the Sun  
> compiler, and the suite is not installed, nor can you install it.  
> Would you try to tweak Makefiles to compile some library with gcc? Or  
> is that just a bad idea and it is better to compile Ruby by hand  
> bypassing the system Ruby and go on from there?

In general, gcc generated code is compatible with system  
compilers.

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/same-compiler-needed-for-c-libraries/81698/3 "2007-01-19T16:31:03Z")

</div>

On Jan 11, 2007, at 3:19 PM, Nobuyoshi N. wrote:

Thank you!

> At Thu, 11 Jan 2007 21:47:47 +0900,  
> Xavier N. wrote in [ruby-talk:233538]:
> 
> > I’ve often heard that the same compiler should be used to compile  
> > Ruby and C extensions. I’ve also heard the same restriction for Perl,  
> > mod\_perl, and Apache. Libraries distributed as binaries for Windows  
> > have to be compiled with Microsoft the compiler as well, right?
> 
> It is not accurate. They have to be compiled with _same  
> version_ of Microsoft compiler, or mingw and VC6.

You mean it is even stronger? Same compiler _and_ same version?

> In general, gcc generated code is compatible with system  
> compilers.

Great, that’s helpful to know. In that case I guess on Solaris I  
could tweak the system-wide mkmf.rb to use gcc and it would work (I  
think the compiler suite is downloadable for free, but in this thread  
I just want to understand what works and what not).

– fxn
