# How to using golang for write a xxx.so for ruby?

**URL:** <https://www.ruby-forum.com/t/how-to-using-golang-for-write-a-xxx-so-for-ruby/179123>\
**Category:** Ruby\
**Created:** [November 18, 2009, 3:50am UTC](https://www.ruby-forum.com/t/how-to-using-golang-for-write-a-xxx-so-for-ruby/179123 "2009-11-18T03:50:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 18, 2009, 3:50am UTC](https://www.ruby-forum.com/t/how-to-using-golang-for-write-a-xxx-so-for-ruby/179123/1 "2009-11-18T03:50:21Z")

</div>

you may see [http://golang.org](http://golang.org)  
I want to using golang create a shared object thant can call from  
ruby,Is it possiable?

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 18, 2009, 12:48pm UTC](https://www.ruby-forum.com/t/how-to-using-golang-for-write-a-xxx-so-for-ruby/179123/2 "2009-11-18T12:48:51Z")

</div>

On 18 Nov 2009, at 02:50, Haoqi H. wrote:

> you may see [http://golang.org](http://golang.org)  
> I want to using golang create a shared object thant can call from  
> ruby,Is it possiable?

First write your shared library in go, then load it into your ruby  
program using either ruby/dl (part of the MRI standard library) or  
ruby-ffi (available as a gem and supported under both MRI and JRuby).

You will also have to figure out how go mangles function names to be  
able to call into the library and there may well be runtime aspects of  
the go language which are incompatible with current ruby  
implementations.

Happy hacking 🙂

Ellie

## Eleanor McHugh Games With Brains [http://slides.games-with-brains.net](http://slides.games-with-brains.net)

raise ArgumentError unless @reality.responds\_to? :reason

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 18, 2009, 11:05pm UTC](https://www.ruby-forum.com/t/how-to-using-golang-for-write-a-xxx-so-for-ruby/179123/3 "2009-11-18T23:05:13Z")

</div>

On Wed, 18 Nov 2009 20:44:20 +0900, Eleanor McHugh wrote:

> Ellie

From the Go FAQ: “There is no safe way to call Go code from C or C++  
yet.”

-jh

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [November 19, 2009, 12:19am UTC](https://www.ruby-forum.com/t/how-to-using-golang-for-write-a-xxx-so-for-ruby/179123/4 "2009-11-19T00:19:33Z")

</div>

On 18 Nov 2009, at 22:01, Jonathan H. wrote:

> > Happy hacking 🙂
> 
> From the Go FAQ: “There is no safe way to call Go code from C or C++ yet.”

Indeed. But if you can build a shared library in the first place  
(something I can’t comment on one way or the other) then both ruby/dl  
and ruby-ffi can attempt to load it. Whether or not that’s easy or  
stable we’ll only know for sure when someone tries 🙂

Ellie

## Eleanor McHugh Games With Brains [http://slides.games-with-brains.net](http://slides.games-with-brains.net)

raise ArgumentError unless @reality.responds\_to? :reason
