简体   繁体   中英

Why does gem not auto compile my C extension

I build a Ruby gem, which needs some C extension. This one - once compiled - is bound via Ruby FFI into the gem.

My setup: I use bundle for the gem scaffolding. Inside my gems folder I have a subfolder ext . This one includes a static Makefile, another subfolder source and an extconf.rb.

The source folder contains all .c and .h files.

The Makefile does not have to be created dynamically. If I call make clean && make in ext everything compiles, and the gem works as expected.

Now I give extconf.rb the following contents:

require 'mkmf'
require 'fileutils'

# Give it a name
extension_name = 'somename'

# The destination
dir_config extension_name

# Do the work
create_makefile extension_name

# Overwrite Makefile
FileUtils.cp 'Makefile.template', 'Makefile'

So I let mkmf create a Makefile first, and overwrite it afterwards by my static template. Stupid.

When I build my gem now via rake build and try to install it on another machine, the extension is not compiled.

Can anyone tell me, what I have to do in order to get the extension compiles automatically on install?

Thanks to the hint of Neil Slater the solution was simple: I did not have gem.extension in my gemspec file like so:

s.extensions    = %w[ext/extconf.rb]

For anyone who faces the same issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM