Extconf.rb and dyld problem

hello people!

just trying to use extconf.rb script using mkmf to compile a bundle for osx (some c++ libraries)

compilation is going ok and linking (even libstdc++) seems ok, but invoking the shared bundle in IRB gives me:

dyld: ruby Undefined symbols:
<snip>
(long list of symbols)

could someone point at the most common reason this happens?

sorry for such n00b question, but just can't figure it out, tried several different LDFLAGS options after googling, and currently have the following options set:

if RUBY_PLATFORM =~ /darwin/
     $CPPFLAGS += " -DUNIX"
     $LDFLAGS += " -lstdc++ -L/usr/local/lib"
     dir_config("fmod","/usr/local/include","/usr/local/lib")
end

if have_header("fmod.h")
     if RUBY_PLATFORM =~ /darwin/
         CONFIG["CC"] = "c++"
         CONFIG["LDSHARED"].gsub!("cc","g++") #make sure you're using g++ so it links libstdc++
         CONFIG['LDSHARED'].gsub!('gcc','g++')
         $create = true if have_library("fmod")
     elsif have_library("fmod") #more than likely a linux box
         CONFIG['LDSHARED'].gsub!('gcc','g++') #make sure c++ gets linked properly
         $create = true
     end
end

any advice?

thanks!

david casal

hello people!

just trying to use extconf.rb script using mkmf to compile a bundle for osx (some c++ libraries)

compilation is going ok and linking (even libstdc++) seems ok, but invoking the shared bundle in IRB gives me:

dyld: ruby Undefined symbols:
<snip>
(long list of symbols)

could someone point at the most common reason this happens?

sorry for such n00b question, but just can't figure it out, tried several different LDFLAGS options after googling, and currently have the following options set:

if RUBY_PLATFORM =~ /darwin/
    $CPPFLAGS += " -DUNIX"
    $LDFLAGS += " -lstdc++ -L/usr/local/lib"
    dir_config("fmod","/usr/local/include","/usr/local/lib")
end

if have_header("fmod.h")
    if RUBY_PLATFORM =~ /darwin/
        CONFIG["CC"] = "c++"
        CONFIG["LDSHARED"].gsub!("cc","g++") #make sure you're using g++ so it links libstdc++
        CONFIG['LDSHARED'].gsub!('gcc','g++')
        $create = true if have_library("fmod")
    elsif have_library("fmod") #more than likely a linux box
        CONFIG['LDSHARED'].gsub!('gcc','g++') #make sure c++ gets linked properly
        $create = true
    end
end

any advice?

thanks!

david casal

From your mail it looks as if you doing your best to use the C++ compiler rather than the standard C compiler. Won't you then be subject to name mangling? Ruby is expecting certain elements under standard names. If those names have been mangled by the C++ compiler it won't find them.

Hi,

At Wed, 6 Apr 2005 22:39:23 +0900,
David Plans Casal wrote in [ruby-talk:137071]:

sorry for such n00b question, but just can't figure it out, tried
several different LDFLAGS options after googling, and currently have
the following options set:

If you need libstdc++, using have_library instead would be best
right now.

  have_library("stdc++")
  dir_config("fmod", "/usr/local")

···

--
Nobu Nakada

Wrote David Plans Casal <dpc@davidcasal.com>, on Wed, Apr 06, 2005 at 10:39:23PM +0900:

hello people!

just trying to use extconf.rb script using mkmf to compile a bundle for
osx (some c++ libraries)

compilation is going ok and linking (even libstdc++) seems ok, but
invoking the shared bundle in IRB gives me:

dyld: ruby Undefined symbols:
<snip>
(long list of symbols)

Could you include some of the symbols?

Ruby expects an extension to have known entry points and those points
must be declared extern C, i.e. to have C linkage:

  extern "C" void Init_MyClass(void);

  ...

  void Init_MyClass(void)
  {
    ...
  }

could this be the problem?

Sam

···

could someone point at the most common reason this happens?

sorry for such n00b question, but just can't figure it out, tried
several different LDFLAGS options after googling, and currently have
the following options set:

if RUBY_PLATFORM =~ /darwin/
    $CPPFLAGS += " -DUNIX"
    $LDFLAGS += " -lstdc++ -L/usr/local/lib"
    dir_config("fmod","/usr/local/include","/usr/local/lib")
end

if have_header("fmod.h")
    if RUBY_PLATFORM =~ /darwin/
        CONFIG["CC"] = "c++"
        CONFIG["LDSHARED"].gsub!("cc","g++") #make sure you're using
g++ so it links libstdc++
        CONFIG['LDSHARED'].gsub!('gcc','g++')
        $create = true if have_library("fmod")
    elsif have_library("fmod") #more than likely a linux box
        CONFIG['LDSHARED'].gsub!('gcc','g++') #make sure c++ gets
linked properly
        $create = true
    end
end

any advice?

thanks!

david casal

--
Sam Roberts <sroberts@certicom.com>

The libraries I'm trying to compile/link are C++, so I thought I -had- to use the C++ compiler?

d

···

On 6 Apr 2005, at 15:33, Peter Wood wrote:

if have_header("fmod.h")
    if RUBY_PLATFORM =~ /darwin/
        CONFIG["CC"] = "c++"
        CONFIG["LDSHARED"].gsub!("cc","g++") #make sure you're using g++ so it links libstdc++
        CONFIG['LDSHARED'].gsub!('gcc','g++')
        $create = true if have_library("fmod")
    elsif have_library("fmod") #more than likely a linux box
        CONFIG['LDSHARED'].gsub!('gcc','g++') #make sure c++ gets linked properly
        $create = true
    end
end

From your mail it looks as if you doing your best to use the C++ compiler rather than the standard C compiler. Won't you then be subject to name mangling? Ruby is expecting certain elements under standard names. If those names have been mangled by the C++ compiler it won't find them.

sorry for such n00b question, but just can't figure it out, tried
several different LDFLAGS options after googling, and currently have
the following options set:

If you need libstdc++, using have_library instead would be best
right now.

  have_library("stdc++")
  dir_config("fmod", "/usr/local")

I included have_library("stdc++") in extconf.rb and took out the LDFLAG stuff calling libstdc++ from there;

I get:

waldorf:~/Development/music/hail-ruby dc$ ./extconf.rb
checking for fmod.h... yes
checking for main() in -lstdc++... yes
checking for main() in -lfmod... yes
creating Makefile

After running make, the bottom of the output reads:

g++ -dynamic -bundle -undefined suppress -flat_namespace -L'/usr/local/lib' -L'/usr/local/lib' -o hail.bundle Audio.o Channel.o Channel2D.o Channel3D.o ChannelEax.o EaxMaterial.o Hail.o Listener.o ListenerEax.o Log.o Manager.o Memory.o RbVector3.o Sample.o Scheduler.o Signal.o Sound.o SparseSwitcher.o Stream.o Timer.o Vector3.o -lruby -lfmod -lstdc++ -ldl -lobjc

And the output of 'sudo make install' gives;

install -c -p -m 0755 hail.bundle /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin
install -c -p -m 0644 ./lib/hail/AudioExtensions.rb /usr/local/lib/ruby/site_ruby/1.8/hail
install -c -p -m 0644 ./lib/hail/CrowdSynth.rb /usr/local/lib/ruby/site_ruby/1.8/hail
install -c -p -m 0644 ./lib/hail/EAX.rb /usr/local/lib/ruby/site_ruby/1.8/hail
install -c -p -m 0644 ./lib/hail/Log.rb /usr/local/lib/ruby/site_ruby/1.8/hail

However, to answer Sam's question below, I'm still getting 'dyld: ruby Undefined symbols'...will list some below:

Could you include some of the symbols?

Ruby expects an extension to have known entry points and those points
must be declared extern C, i.e. to have C linkage:

waldorf:~/Development/music/hail-ruby dc$ irb
irb(main):001:0> require 'hail'
dyld: ruby Undefined symbols:
_AbsoluteToDuration
_AddDurationToAbsolute
_BitClr
_BitTst
_CloseOpenTransportInContext
_Dequeue
_DisposePtr
_Enqueue
_Fix2Long

<snip>

_SndDoImmediate
_SndNewC_SndSoundManagerVersion
_UpTime
_YieldToAnyThread
__MPIsFullyInitialized
Trace/BPT trap

Unfortunately, I'm not sure what Sam means by 'entry points', due my total lack of C and newbie programmer skills in Ruby...

Does this throw more light on the problem?

Hope you guys see something I don't...

d

···

On 6 Apr 2005, at 15:38, nobu.nokada@softhome.net wrote:
On 6 Apr 2005, at 15:39, Sam Roberts wrote:

Apologies, I should have been more specific. Where you mix C and C++ code you must explicitly pick out the elements that to be treated in the C way from those that will be handled in the C++ way. Another mail on this topic has already referred to marking the initialization function with extern "C". You may have to do this for other elements as well, although an exact list of what requires it will depend on the symbols that are missing.

···

On 6 Apr 2005, at 15:33, Peter Wood wrote:

if have_header("fmod.h")
    if RUBY_PLATFORM =~ /darwin/
        CONFIG["CC"] = "c++"
        CONFIG["LDSHARED"].gsub!("cc","g++") #make sure you're using g++ so it links libstdc++
        CONFIG['LDSHARED'].gsub!('gcc','g++')
        $create = true if have_library("fmod")
    elsif have_library("fmod") #more than likely a linux box
        CONFIG['LDSHARED'].gsub!('gcc','g++') #make sure c++ gets linked properly
        $create = true
    end
end

From your mail it looks as if you doing your best to use the C++ compiler rather than the standard C compiler. Won't you then be subject to name mangling? Ruby is expecting certain elements under standard names. If those names have been mangled by the C++ compiler it won't find them.

The libraries I'm trying to compile/link are C++, so I thought I -had- to use the C++ compiler?

d

These furiously look like Carbon calls. You should try to link against
the Carbon framework using the '-framework Carbon' in the link options.

···

David Plans Casal <dpc@davidcasal.com> wrote:

waldorf:~/Development/music/hail-ruby dc$ irb
irb(main):001:0> require 'hail'
dyld: ruby Undefined symbols:
_AbsoluteToDuration
_AddDurationToAbsolute
_BitClr
_BitTst
_CloseOpenTransportInContext
_Dequeue
_DisposePtr
_Enqueue
_Fix2Long

<snip>

_SndDoImmediate
_SndNewC_SndSoundManagerVersion
_UpTime
_YieldToAnyThread
__MPIsFullyInitialized
Trace/BPT trap

--
Luc Heinrich - lucsky@mac.com

I include my extconf.rb here complete, for reference, in case it helps:

#!/usr/local/bin/ruby
require 'mkmf'

$create = false

if ARGV.include?("--help")
     print <<EOF
     --with-fmod-include specify directory for fmod include files
     --with-fmod-lib specify directory for fmod library files
EOF
     exit(0)
end

if RUBY_PLATFORM =~ /darwin/
     $CPPFLAGS += " -DUNIX"
     $LDFLAGS += " "
     dir_config("fmod","/usr/local/include","/usr/local/lib")
end

if have_header("fmod.h")
     if RUBY_PLATFORM =~ /darwin/
         CONFIG["CC"] = "c++"
         CONFIG["LDSHARED"].gsub!("cc","g++")
  CONFIG['LDSHARED'].gsub!('gcc','g++')
  have_library("stdc++")
         $create = true if have_library("fmod")
     elsif have_library("fmod") #more than likely a linux box
         CONFIG['LDSHARED'].gsub!('gcc','g++') #make sure c++ gets linked properly
         $create = true
     end
end
  if $create
     create_makefile("hail")
else
     puts 'your system is not correctly setup to build hail'
     puts 'look in mkmf.log to figure out why.'
end

I'm sorry if this is a waste of your time (I mean that I may not even understand your advice)...but the thing is this set of ruby bindings came from the author, who is able to compile them in linux just fine, and comes with ruby examples that use the linked c++ libraries he wrote.

What I'm wondering here is: perhaps my problem is simply to do with the darwin platform differences with linux, and that extconf.rb was written for linux?

I say this because I hope that's the case :wink: ... since if the problem is what you outline, I'm probably not going to be able to do much about it...

Cheers,

David

···

On 6 Apr 2005, at 16:01, Peter Wood wrote:

The libraries I'm trying to compile/link are C++, so I thought I -had- to use the C++ compiler?

Apologies, I should have been more specific. Where you mix C and C++ code you must explicitly pick out the elements that to be treated in the C way from those that will be handled in the C++ way. Another mail on this topic has already referred to marking the initialization function with extern "C". You may have to do this for other elements as well, although an exact list of what requires it will depend on the symbols that are missing.

Do you mean like this?

if RUBY_PLATFORM =~ /darwin/
     $CPPFLAGS += " -DUNIX"
     $LDFLAGS += " -framework Carbon"
     dir_config("fmod","/usr/local/include","/usr/local/lib")
end

d

···

On 6 Apr 2005, at 16:24, Luc Heinrich wrote:

David Plans Casal <dpc@davidcasal.com> wrote:

_AbsoluteToDuration
_AddDurationToAbsolute

These furiously look like Carbon calls. You should try to link against
the Carbon framework using the '-framework Carbon' in the link options.

Oh MY. That worked, I think!

Thank you all for all the help!

Cheers,

David Casal

···

On 6 Apr 2005, at 16:32, David Plans Casal wrote:

On 6 Apr 2005, at 16:24, Luc Heinrich wrote:

David Plans Casal <dpc@davidcasal.com> wrote:

_AbsoluteToDuration
_AddDurationToAbsolute

These furiously look like Carbon calls. You should try to link against
the Carbon framework using the '-framework Carbon' in the link options.

Do you mean like this?

if RUBY_PLATFORM =~ /darwin/
    $CPPFLAGS += " -DUNIX"
    $LDFLAGS += " -framework Carbon"
    dir_config("fmod","/usr/local/include","/usr/local/lib")
end