問題描述
我是一名經(jīng)驗(yàn)豐富的 C/C++ 開發(fā)人員,但我是 Ruby 的新手.
如何在 Ruby 中調(diào)用 C++ 函數(shù)?
你有 3 種可能性:
1) Ruby 能夠加載庫(kù).即使有點(diǎn)棘手,您也可以決定編寫自己的加載程序并在 Ruby 中綁定您的 C++ 庫(kù).這是使用所謂的擴(kuò)展模塊完成的.您可以在此處找到綜合教程:http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html>
2) 您可以使用工具來圍繞您的 C++ 庫(kù)生成 Ruby 包裝器.以 SWIG 為例(http://www.swig.org/).您只需要以特定于 swig 的語法創(chuàng)建一個(gè)文件并將其提供給 SWIG.然后它將能夠?yàn)榘?Ruby 在內(nèi)的多種語言生成包裝器.
3) 您可以選擇使用中間件,例如 CORBA/ICE/whatever.如果你只想調(diào)用一些 C++ 函數(shù)可能有點(diǎn)矯枉過正,但它可以讓你遠(yuǎn)程調(diào)用這些函數(shù),或者在中間件后面隱藏"一個(gè)網(wǎng)格.
I am an experienced C/C++ developer but I am a novice in Ruby.
How can I call a C++ function from with in Ruby?
You have 3 possibilities :
1) Ruby is able to load libraries. Even if it is a bit tricky, you can decide to write your own loader and bind your C++ library in Ruby. This is done using what is called an extension module. You will find a comprehensive tutorial here: http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html
2) You can use a tool that will generate the Ruby wrapper around your C++ library. Look at SWIG for example (http://www.swig.org/). You just have to create a file in a swig-specific syntax and provide it to SWIG. It will then be able to generate the wrapper for many languages, Ruby included.
3) You can choose to use a middleware, such as CORBA/ICE/whatever. It may be a bit overkill if you only want to call some C++ functions, but it will allow you to remote call the functions, or "hide" a grid behind the middleware.
這篇關(guān)于如何從 ruby?? 中調(diào)用 C++ 函數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!