Question

I have the following files in this directory:

~/test/lib/liblost.dylib
~/test/include/lost.h

I am trying to let my rubygem determine if the above library exists by doing the following in irb:

ruby-1.9.2-p290 :008 > dir_config('','~/test')
 => ["~/test/include", "~/test/lib"] 
ruby-1.9.2-p290 :009 > have_library('lost')
checking for main() in -llost... no
 => false 

Can someone please explain why this isn't working?

Was it helpful?

Solution

This looks like it's due to using ~ to specify the home directory. The shell only expands ~ to the path of your home directory if it is the first character of a word. When mkmf constructs the command line to call the compiler to check for the existence of the library it specifies the directory to call using the -L option, and it ends up looking like -L~/test/lib, and so isn't expanded. You should be able to see this in the mkmf.log file.

The fix is to avoid the ~ character in the directory path, or ensure it gets expanded before it gets used in the call to the compiler.

You could do this by changing dir_config('','~/test') to:

dir_config('', File.expand_path('~/test'))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top