LoginSignup
6
7

More than 5 years have passed since last update.

C++からRubyを呼び出す

Posted at

環境

$ g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

$ pkg-config --version
0.29.1

$ ruby --version
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]
main.cpp
#include <ruby.h>

int main() {
  // Rubyインタプリタの初期化
  ruby_init();

  // スクリプトの実行
  rb_eval_string("print 'Hello World!'");

  // Rubyインタプリタのクリーンアップ
  ruby_cleanup(0);
}

Build

$ g++ `pkg-config --cflags ruby-2.3` -lopencv_core -lopencv_highgui -lopencv_imgproc main.cpp `pkg-config --libs ruby-2.3`

Usage

$ ./a.out
Hello World!%

参考資料

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7