From: Tim Pease Date: 2007-04-14T23:39:11+09:00 Subject: Re: Nuby question on using C++ with Swig - issues with cout On 4/13/07, james.d.masters@gmail.com wrote: > I am looking into using Swig to bring some C++ libraries into Ruby. > I'm not extremely C++ proficient, but know the basics. Anyway, I'm > having issues with using "cout" within Swig. I've put together a > small test case here: > > === hello.h === > #include > void hello_world() { > std::cout << "hello world"; > } > > === hello.i === > %module example > %{ > #include "hello.h" > %} > %include "hello.h" > > === extconf.rb === > require 'mkmf' > $libs = append_library($libs, "supc++") > create_makefile('hello') > > Commands: > > % swig -c++ -ruby hello.i > % ruby extconf.rb > % make > % ruby -e 'require "hello"' > ./hello.so: ./hello.so: undefined symbol: _ZSt4cout - ./hello.so > (LoadError) > from -e:1 > > Please help me on this... is this an issue with dynamic linking? C++ name mangling problem. You need to put extern "C" around your method. === hello.h === #include #ifdef __cplusplus extern "C" { #endif void hello_world() { std::cout << "hello world"; } #ifdef __cplusplus } #endif Blessings, TwP