From 7e17b17efb3c7324f4de6ff641e38e4154d8b4f6 Mon Sep 17 00:00:00 2001 From: Max Anselm Date: Wed, 5 Jun 2024 08:27:10 -0400 Subject: [PATCH] add rbconfig method of determining compiler opts --- Gemfile.lock | 1 + _posts/2012-01-01-embed.markdown | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 542f4fb..0b20f48 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,6 +59,7 @@ GEM webrick (1.7.0) PLATFORMS + arm64-darwin-21 x86_64-darwin-19 x86_64-linux diff --git a/_posts/2012-01-01-embed.markdown b/_posts/2012-01-01-embed.markdown index dda9dbb..dc110a9 100644 --- a/_posts/2012-01-01-embed.markdown +++ b/_posts/2012-01-01-embed.markdown @@ -14,13 +14,18 @@ On my machine, my minimal compiler options are $ gcc foo.c -I/usr/include/ruby-{{ site.rbversion }}.0 -I/usr/include/ruby-{{ site.rbversion }}.0/x86_64-linux -lruby {% endhighlight %} -Though, if available, you should really use `pkg-config` to get the appropriate -options for your distribution: +If available, you can use `pkg-config` to get the appropriate options for your OS: {% highlight shell_session %} $ pkg-config --cflags --libs ruby-{{ site.rbversion }} {% endhighlight %} +Alternatively, you can ask Ruby itself what the compiler options should be: + +{% highlight shell_session %} +$ ruby -rshellwords -e 'puts "-I#{Shellwords.escape RbConfig::CONFIG["rubyhdrdir"]} -I#{Shellwords.escape RbConfig::CONFIG["rubyarchhdrdir"]} -L#{Shellwords.escape RbConfig::CONFIG["libdir"]} -lruby"' +{% endhighlight %} + ## Startup, Teardown ## Including the Ruby interpreter in your C/C++ program is pretty simple. Just