From: google@... (Bheeshmar Redheendran) Date: 2004-03-26T12:04:28+09:00 Subject: Ruby/DL and C++ libraries I'm trying to use a C++ shared library from Ruby and wanted to use Ruby/DL to do it. It seemed straightforward enough, but I can't seem to match the signature on the function I want to import. Here's a simplified example: ------------------------------------------------------------------- bash $ cat dlexample.cpp #include #include extern "C" void place( const std::string &text) { std::cout << text << std::endl ; } bash $ cat dlexample.rb require 'dl/import' module Test extend DL::Importable dlload 'dlexample.so' typealias 'string', 'p' extern "void place(string)" end Test.place("text") bash $ g++ -shared -fPIC -o dlexample.so dlexample.cpp bash $ LD_LIBRARY_PATH="." ruby dlexample.rb (eval):5: [BUG] Segmentation fault ruby 1.8.1 (2004-02-06) [x86_64-linux-gnu] Aborted ------------------------------------------------------------------- It works with C functions (change the "const std::string &" to a "const char *" and it's all good). I have a feeling this can work with the write typealias and encoding functions, but I'm fairly new to Ruby and would appreciate any pointers. I have a workaround in place using Swig, but if I go that route, I may as well just code up the utility in C++. Thanks in advance, Bheeshmar Redheendran