我已经看到很多指南谈论在ruby gem中使用extconf.rb和c扩展名。我认为这不适合我的用例,因为我要捆绑的C程序使用文件来完成工作。

有人建议我将kdiff3列为我的gem中的要求,但是我在代码中添加了一些功能,谁知道何时将其推送到所有程序包控制存储库。

总而言之,这就是我想要做的
 -编译存储库中的C代码(makefile已经存在,并使用./configure qt4进行编译)
 -希望在gem安装时进行编译

这是我的宝石:https://github.com/NullVoxPopuli/kdiff3-rb
ext / kdiff3目录是https://github.com/NullVoxPopuli/kdiff3中的git子树

最佳答案

最终成为我“解决”问题的方式。有点破解,但功能强大。

https://github.com/NullVoxPopuli/kdiff3-rb/blob/master/ext/kdiff3/extconf.rb

# Unconventional way of extconf-ing
# http://yorickpeterse.com/articles/hacking-extconf-rb/
require 'mkmf'

# Stops the installation process if one of these commands is not found in
# $PATH.
find_executable('make')
find_executable('qmake')
# create fake Makefile, courtesy of
# https://github.com/leejarvis/ruby-c-example/tree/master/ext/hello
# it's ugly, and a hack, but it continues the gem install process.
# hello.c is small and meaningless in the context if this repository.
create_makefile('hello')

# build kdiff3
# - currently has to compile with qt4
#   maybe someday, qt4 can be optional
Dir.chdir('./') do
  exec './configure qt4'
end

# fail if compiling didn't succeed
unless File.exist?('releaseQT/kdiff3')
  abort("\nERROR:  kdiff3 was not successfully compiled")
end

关于ruby-on-rails - 如何通过C程序的命令行界面编译C程序以与我的ruby gem一起使用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27409862/

10-13 05:28