Skip to content

Commit

Permalink
add rbconfig method of determining compiler opts
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Anselm committed Jun 5, 2024
1 parent 0a45a7d commit 7e17b17
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ GEM
webrick (1.7.0)

PLATFORMS
arm64-darwin-21
x86_64-darwin-19
x86_64-linux

Expand Down
9 changes: 7 additions & 2 deletions _posts/2012-01-01-embed.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e17b17

Please sign in to comment.