問題描述
我是一名經驗豐富的 C/C++ 開發人員,但我是 Ruby 的新手.
如何在 Ruby 中調用 C++ 函數?
你有 3 種可能性:
1) Ruby 能夠加載庫.即使有點棘手,您也可以決定編寫自己的加載程序并在 Ruby 中綁定您的 C++ 庫.這是使用所謂的擴展模塊完成的.您可以在此處找到綜合教程:http://www.rubyinside.com/how-to-create-a-ruby-extension-in-c-in-under-5-minutes-100.html>
2) 您可以使用工具來圍繞您的 C++ 庫生成 Ruby 包裝器.以 SWIG 為例(http://www.swig.org/).您只需要以特定于 swig 的語法創建一個文件并將其提供給 SWIG.然后它將能夠為包括 Ruby 在內的多種語言生成包裝器.
3) 您可以選擇使用中間件,例如 CORBA/ICE/whatever.如果你只想調用一些 C++ 函數可能有點矯枉過正,但它可以讓你遠程調用這些函數,或者在中間件后面隱藏"一個網格.
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.
這篇關于如何從 ruby?? 中調用 C++ 函數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!