From: Joshua Ballanco Date: 2008-03-24T08:03:28+09:00 Subject: Re: extending ruby with C++ 7stud -- wrote: >> Where do those statements go? Inside extconf.rb? > > My current extconf.rb file: > > require 'mkmf' > > if (/mswin32/ =~ PLATFORM) > $CFLAGS+=" -GX " # allow exceptions > end > > $LIBS << " -lstdc++ -lc" > $CC =="g++" > $CXX == $CC > > create_makefile("Test") > > The output: > > $ ruby extconf.rb > creating Makefile > > $ make > g++ -fno-common -g -Os -pipe -fno-common -pipe -fno-common -pipe > -fno-common -I. -I/usr/lib/ruby/1.8/universal-darwin8.0 > -I/usr/lib/ruby/1.8/universal-darwin8.0 -I. -c Test.cpp > cc -bundle -L"/usr/lib" -o Test.bundle Test.o -lruby -lpthread -ldl > -lobjc -lstdc++ -lc > /usr/bin/ld: Undefined symbols: > __Unwind_Resume > collect2: ld returned 1 exit status > make: *** [Test.bundle] Error 1 > > $ls > Makefile Test.cpp Test.o extconf.rb I've run into this problem myself on OS X. For some reason, the mkmf library in Ruby 1.8 fails to properly realize that it should use g++ instead of gcc or cc for C++ files. (Luckily Ruby 1.9 doesn't have this problem ATM.) You need to explicitly tell mkmf to use g++ like so: cpp_command('g++') There's also the arch flags issue to worry about (Ruby, by default, tries to build universal, but many libraries build only one arch on OS X). I've com up with a fix for that as well. Including it you're extconf.rb should look like: require 'mkmf' require 'rbconfig' if Config::CONFIG["arch"] =~ /universal-darwin/ case `uname -smr`.chomp when "i386" : ENV['ARCHFLAGS'] = '-arch i386' when "ppc" : ENV['ARCHFLAGS'] = '-arch ppc' end cpp_command('g++') if RUBY_VERSION < '1.9' end if (/mswin32/ =~ PLATFORM) $CFLAGS+=" -GX " # allow exceptions end create_makefile("Test") -- Posted via http://www.ruby-forum.com/.