extconf.rb and dyld problem

  • Thread starter David Plans Casal
  • Start date
D

David Plans 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
 
P

Peter Wood

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.
 
N

nobu.nokada

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")
 
S

Sam Roberts

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
 
D

David Plans Casal

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
 
D

David Plans Casal

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
 
P

Peter Wood

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

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.
 
L

Luc Heinrich

David Plans Casal said:
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

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

David Plans Casal

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
 
D

David Plans Casal

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.

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 ;-) ... since if the
problem is what you outline, I'm probably not going to be able to do
much about it...

Cheers,

David
 
D

David Plans Casal

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

d
 
D

David Plans Casal

Do you mean like this?

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

Oh MY. That worked, I think!

Thank you all for all the help!

Cheers,

David Casal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top