# Best way to get compile-time configuration for building/linking against Ruby?

**URL:** <https://www.ruby-forum.com/t/best-way-to-get-compile-time-configuration-for-building-linking-against-ruby/194823>\
**Category:** Ruby\
**Created:** [September 11, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/best-way-to-get-compile-time-configuration-for-building-linking-against-ruby/194823 "2010-09-11T15:56:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_MSP\_Veith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecd19e/32.png) [@Eric\_MSP\_Veith](https://www.ruby-forum.com/u/Eric_MSP_Veith)\
**Post date:** [September 11, 2010, 3:56pm UTC](https://www.ruby-forum.com/t/best-way-to-get-compile-time-configuration-for-building-linking-against-ruby/194823/1 "2010-09-11T15:56:34Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hello list,

I want to embed the Ruby interpreter in a project and am currently  
fiddeling  
with getting Ruby’s compile-time configuration, e.g. include and  
libraries  
paths. I cannot use ‘mkmf’ for various reasons.

Currently, I’m running something like that:

- —%\<—  
ruby -rrbconfig -e ‘puts  
RbConfig::expand("#{RbConfig::CONFIG[“rubyhdrdir”]}/$(arch)")’
- —\>%—

I trust there is a better/more elegant way of solving this? If so, what  
would it be?

Thanks a lot in advance,  
Eric

P. S. Any chance the Ruby sources would include a pkg-config file or  
something similar in the near future?  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkyLiVkACgkQhS0drJ3goJIuDgCfdi5BFxOyLKRwT2frpbqvLRi/  
rXoAnit39lRbdsdghe0ESM3K7W9fGo1B  
=qJTI  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![Eric\_MSP\_Veith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecd19e/32.png) [@Eric\_MSP\_Veith](https://www.ruby-forum.com/u/Eric_MSP_Veith)\
**Post date:** [September 11, 2010, 5:39pm UTC](https://www.ruby-forum.com/t/best-way-to-get-compile-time-configuration-for-building-linking-against-ruby/194823/2 "2010-09-11T17:39:01Z")

</div>

> paths. I cannot use ‘mkmf’ for various reasons.

I would call out to mkmf with a fake ext and “see” what it uses.  
-r

---

<div class="post-metadata">

**Author:** ![Eric\_MSP\_Veith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecd19e/32.png) [@Eric\_MSP\_Veith](https://www.ruby-forum.com/u/Eric_MSP_Veith)\
**Post date:** [September 11, 2010, 5:47pm UTC](https://www.ruby-forum.com/t/best-way-to-get-compile-time-configuration-for-building-linking-against-ruby/194823/3 "2010-09-11T17:47:11Z")

</div>

> I trust there is a better/more elegant way of solving this? If so, what

i use this

[gist:575279 · GitHub](http://gist.github.com/575279)

makes it simple to import the output into any program that can parse  
yaml|json.

-a

---

<div class="post-metadata">

**Author:** ![Eric\_MSP\_Veith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecd19e/32.png) [@Eric\_MSP\_Veith](https://www.ruby-forum.com/u/Eric_MSP_Veith)\
**Post date:** [September 11, 2010, 6:11pm UTC](https://www.ruby-forum.com/t/best-way-to-get-compile-time-configuration-for-building-linking-against-ruby/194823/4 "2010-09-11T18:11:11Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Roger,  
Ara,

thanks for your answers. I should have been a bit clearer with my  
request;  
sorry.

Thing is, I’m using Autotools (autoconf et al), so I cannot hardcore  
paths  
for obvious reasons, and parsing JSON or YAML is from the table, too.  
So,  
“more elegant” basically meant: Something that’s easy to use from a  
shell  
script (i.e., configure.ac).

Does sombody have another suggestion? 🙂

```
  Eric

```

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkyLp6gACgkQhS0drJ3goJKhPgCeOeOS+aXsju/RbP6kxkyvcJ0S  
rsQAn3oZE2fWFoSKmdqZwGielp5wxWKd  
=EOp6  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![Eric\_MSP\_Veith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ecd19e/32.png) [@Eric\_MSP\_Veith](https://www.ruby-forum.com/u/Eric_MSP_Veith)\
**Post date:** [September 11, 2010, 11:00pm UTC](https://www.ruby-forum.com/t/best-way-to-get-compile-time-configuration-for-building-linking-against-ruby/194823/5 "2010-09-11T23:00:57Z")

</div>

On Sep 11, 1:01 pm, Eric MSP Veith [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> for obvious reasons, and parsing JSON or YAML is from the table, too. So,  
> “more elegant” basically meant: Something that’s easy to use from a shell  
> script (i.e., configure.ac).
> 
> Does sombody have another suggestion? 🙂

A workaround will be create ruby as static library (–enable-static –  
disable-shared) during Ruby configure phase.

Then, create a program entry point (your program) and link against  
libruby library.

You can check how that is done for projects like exerb, is Windows and  
MinGW, but you can get the idea form it:

> **[GitHub - snaury/exerb-mingw: Exerb support for mingw/rubyinstaller](https://github.com/snaury/exerb-mingw)**
>
> Exerb support for mingw/rubyinstaller. Contribute to snaury/exerb-mingw development by creating an account on GitHub.

HTH,
