[英]Ruby C extension gem doesn't compile at installation
I have a little project that I want to share via a gem. 我有一个小项目,想通过gem分享。 This extension must be compiled on the user system. 此扩展名必须在用户系统上编译。 So the compilation must be done when the gem is installed. 因此,必须在安装gem时完成编译。
My project is simple: 我的项目很简单:
tree
├── myext.gemspec
├── ext
│ └── myext
│ └── myext.c
│ └── extconf.rb
├── lib
│ ├── myext
│ └── myext.rb
├── Rakefile
└── test
I have checked the extconf.rb and the compilation works if I do 我已经检查了extconf.rb和编译工作,如果我这样做
ruby extconf.rb && make
I have a myext.gemspec: 我有一个myext.gemspec:
Gem::Specification.new do |s|
s.name = 'myext'
s.version = '0.0.1'
s.date = '2015-04-22'
s.summary = "an extension"
s.description = "an extension that is mine"
s.authors = ["cedlemo"]
require "rake" #for FileList
s.files = FileList['lib/*/*.{so}',
'lib/*.{rb}'
].to_a
s.extensions = %w(ext/myext/extconf.rb)
s.add_development_dependency 'rake-compiler', '~> 0'
s.license = 'MIT'
end
and here is my Rakefile : 这是我的Rakefile:
require "rubygems"
require "rake/extensiontask"
spec = Gem::Specification.load('myext.gemspec')
Rake::ExtensionTask.new "myext", spec do |ext|
ext.lib_dir = "lib/myext"
end
When I build my gem, everything is fine : 当我制造宝石时,一切都很好:
gem build myext.gemspec
And when I install the gem I havn't any error message: 而且当我安装gem时,没有任何错误消息:
gem install myext-0.0.1.gem
Building native extensions. This could take a while...
Successfully installed myext-0.0.1
1 gem installed
My problem is that the C code is not compiled and I don't have any .so file installed: 我的问题是C代码未编译,并且我没有安装任何.so文件:
/home/cedlemo/.gem/ruby/2.2.0/gems/myext-0.0.1/
├── ext
│ └── myext
│ ├── extconf.rb
│ └── Makefile
└── lib
└── myext.rb
PS: I have read a lot of documentations (official or blogs ...) and everybody is doing its own stuff so it is not very clear and I can't find a solution so don't send me link to http://guides.rubygems.org/ for example. PS:我已经阅读了很多文档(官方或博客...),每个人都在做自己的事情,所以它不是很清楚,我找不到解决方案,所以请不要发送链接到http://例如guides.rubygems.org/ 。
You haven't included the source files in your files
part of your gemspec
, so there is nothing to compile when installing the gem. 您没有在gemspec
files
部分中包含源文件,因此在安装gem时无需编译。 Make sure you include all needed files: 确保包括所有需要的文件:
s.files = FileList['lib/**/*.rb', 'ext/**/*.{rb,c,h}']
You don't need to include .so
files, as they will be built during installation (and might not actually be .so
). 您不需要包括.so
文件,因为它们将在安装过程中生成(实际上可能不是.so
)。 Also I don't think you need to add to_a
(a FileList
basically is an array already). 我也不认为您需要添加to_a
(一个FileList
基本上已经是一个数组)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.