如何让Ruby找到一个本地库? [英] How to get Ruby to find a native lib?

查看:99
本文介绍了如何让Ruby找到一个本地库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在/ usr / local / lib中安装了一些本地库。



我正在尝试安装一个需要这些以便
构建的gem但是,由于无法找到
库,所以创建gem失败。



gem的extconf.rb文件试图确认它可以找到带有$ b的库$ b have_library()但是由于某种原因失败了。



我尝试设置一堆环境变量,似乎工作:

  irb(main):003:0>要求'mkmf'
=> true
irb(main):004:0> have_library('gecodesearch')
检查main()in -lgecodesearch ... no
=> false
irb(main):005:0> ENV ['LD_LIBRARY_PATH'] ='/ usr / local / lib'
=> / usr / local / lib
irb(main):006:0> have_library('gecodesearch')
检查main()in -lgecodesearch ... no
=> false
irb(main):007:0> ENV ['DYLD_LIBRARY_PATH'] ='/ usr / local / lib'
=> / usr / local / lib
irb(main):008:0> have_library('gecodesearch')
检查main()in -lgecodesearch ... no
=> false
irb(main):009:0> have_library('libgecodesearch')
在-llibgecodesearch中检查main()... no
=> false
irb(main):010:0> ENV ['C_INCLUDE_PATH'] ='/ usr / local / lib'
=> / usr / local / lib
irb(main):011:0> have_library('gecodesearch')
检查main()in -lgecodesearch ... no
=> false
irb(main):012:0> ENV ['PATH'] ='/ usr / local / lib'
=> / usr / local / lib
irb(main):013:0> have_library('gecodesearch')
检查main()in -lgecodesearch ... no
=> false

解决这个问题的最佳方法是什么?

解决方案

我已阅读了评论,并且我知道您已将其付诸实施,但我认为我有适当的解决方案。



have_library 检查是否可以在您的环境中使用给定的库。它通过包含库头并将其一个函数用于临时C源文件中来实现。

  have_library'geocodesearch'
检查main()in -lgecodesearch ... no

have_library could不要使用 geocodesearch 中的 main 函数。这或者意味着库不可用或者该函数不存在。在你的情况下,它可能是后者。



你可以告诉 have_library 论据。例如:

$ p $ have_library'geocodesearch','geocodesearch_version'
检查geocodesearch_version()in -lgecodesearch ...

如果您不指定,它只会查找 main 函数。您还可以指定要包含的标题:

  have_library'geocodesearch','geocodesearch_version',%w(地理编码/搜索。 h)

在评论中,您说过通过简单地消除 have_library 调用。这是一个本地化解决方案;您必须将其重新应用于任何新版本的gem。



我建议向包含必要调整的作者发送拉取请求。这个错误将会被永久修复,你也会帮助那些可能会遇到同样问题的人。

mkmf 参考:




I installed some native libraries in /usr/local/lib.

I am now trying to install a gem which needs these in order to build correctly but, the gem build fails as it cannot find the libraries.

The gem's extconf.rb file tries to confirm it can find the library with have_library() but this fails for some reason.

I tried setting a bunch of environment variables but nothing seems to work:

irb(main):003:0> require 'mkmf'
=> true
irb(main):004:0> have_library('gecodesearch')
checking for main() in -lgecodesearch... no
=> false
irb(main):005:0> ENV['LD_LIBRARY_PATH']='/usr/local/lib'
=> "/usr/local/lib"
irb(main):006:0> have_library('gecodesearch')
checking for main() in -lgecodesearch... no
=> false
irb(main):007:0> ENV['DYLD_LIBRARY_PATH']='/usr/local/lib'
=> "/usr/local/lib"
irb(main):008:0> have_library('gecodesearch')
checking for main() in -lgecodesearch... no
=> false
irb(main):009:0> have_library('libgecodesearch')
checking for main() in -llibgecodesearch... no
=> false
irb(main):010:0> ENV['C_INCLUDE_PATH']='/usr/local/lib'
=> "/usr/local/lib"
irb(main):011:0> have_library('gecodesearch')
checking for main() in -lgecodesearch... no
=> false
irb(main):012:0> ENV['PATH']='/usr/local/lib'
=> "/usr/local/lib"
irb(main):013:0> have_library('gecodesearch')
checking for main() in -lgecodesearch... no
=> false 

What is the best way to solve this problem?

解决方案

I've read the comments and I know you made it work, but I think I have the proper solution to the problem.

have_library checks whether it is possible to use the given library in your environment. It does so by including the library header and using one of its functions in a temporary C source file. If it is successful, then the library must be available.

have_library 'geocodesearch'
checking for main() in -lgecodesearch... no

have_library could not use the mainfunction from geocodesearch. This either means the library is not available or the function doesn't exist. In your case, it is probably the latter.

You can tell have_library which function to try by passing a second argument. For example:

have_library 'geocodesearch', 'geocodesearch_version'
checking for geocodesearch_version() in -lgecodesearch...

If you don't specify, it will simply look for the main function. You can also specify the headers to be included:

have_library 'geocodesearch', 'geocodesearch_version', %w(geocode/search.h)

In the comments, you said you solved your problem by simply eliminating the have_library calls. This is a localized solution; you will have to reapply it to any new versions of the gem.

I recommend sending a pull request to the author containing the necessary adjustments. The bug will be permanently fixed and you will also help others who might be having the same issue.

mkmf reference:

这篇关于如何让Ruby找到一个本地库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆