# In an ruby c extension, How to link it with a shared library

**URL:** <https://www.ruby-forum.com/t/in-an-ruby-c-extension-how-to-link-it-with-a-shared-library/95861>\
**Category:** Ruby\
**Created:** [June 16, 2006, 10:29am UTC](https://www.ruby-forum.com/t/in-an-ruby-c-extension-how-to-link-it-with-a-shared-library/95861 "2006-06-16T10:29:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![huiliang\_wu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@huiliang\_wu](https://www.ruby-forum.com/u/huiliang_wu)\
**Post date:** [June 16, 2006, 10:29am UTC](https://www.ruby-forum.com/t/in-an-ruby-c-extension-how-to-link-it-with-a-shared-library/95861/1 "2006-06-16T10:29:31Z")

</div>

Hi,  
I have a simple shared library written in c++ and named libfoo.so, the  
header files is:  
#ifndef FOO\_H  
#define FOO\_H

#ifdef \_\_cplusplus  
extern “C”  
{  
#endif

void say(const char \*pSentence);

#ifdef \_\_cplusplus  
}  
#endif

#endif

When I use `nm libfoo.so | grep say`, I can get such result:  
00000916 t \_GLOBAL\_\_I\_say  
00000858 T say

But when I use have\_library(“foo”, “say”) in extconfig.rb, it fails.  
Previously I compile libfoo.so in c, and it can find this library.  
I don’t why this happens, could you help me?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![huiliang\_wu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/bcef8e/32.png) [@huiliang\_wu](https://www.ruby-forum.com/u/huiliang_wu)\
**Post date:** [June 16, 2006, 4:08pm UTC](https://www.ruby-forum.com/t/in-an-ruby-c-extension-how-to-link-it-with-a-shared-library/95861/2 "2006-06-16T16:08:10Z")

</div>

Hi,

At Fri, 16 Jun 2006 17:27:34 +0900,  
huiliang wu wrote in [ruby-talk:197613]:

> But when I use have\_library(“foo”, “say”) in extconfig.rb, it fails.  
> Previously I compile libfoo.so in c, and it can find this library.

A shared library created with C++ compiler would need also C++  
runtime library to link. have\_library doesn’t support C++  
directly yet. If you use g++, try have\_library(“stdc++”)  
before “foo”.
