mkmf编译C扩展名时忽略子文件夹中的文件

mkmf编译C扩展名时忽略子文件夹中的文件,c,ruby,mkmf,ruby-c-extension,C,Ruby,Mkmf,Ruby C Extension,我想这样组织C源代码: + / | |___ + ext | | | |___ + native_extension | | | |___ + lib | | | | | |___ (Source files are kept in here - may contain sub-folders) | | | |___ native_extension.c | |

我想这样组织C源代码:

+ /
|
|___ + ext
|    |
|    |___ + native_extension
|         |
|         |___ + lib
|         |    |
|         |    |___ (Source files are kept in here - may contain sub-folders)
|         |
|         |___ native_extension.c
|         |___ native_extension.h
|         |___ extconf.rb
|
|___ + lib
|    |
|    |___ (Ruby source code)
|
|___ Rakefile
require 'mkmf'

extension_name = 'native_extension'
dir_config(extension_name)

# enum all source files
$srcs = ["native_extension.c", "lib/file.c"]

# add include path to the internal folder
# $(srcdir) is a root folder, where "extconf.rb" is stored
$INCFLAGS << " -I$(srcdir)/lib"

# add folder, where compiler can search source files
$VPATH << "$(srcdir)/lib"

create_makefile(extension_name)
我无法使此设置与
mkmf
一起正常工作。
native_extension/lib
中包含在
native_extension.c
中的文件将被完全忽略

当我构建扩展时,只编译
native_扩展。{h,c}
,我得到一个不完整的
native_扩展。{so,dll}
,当我尝试运行它时,它会给我符号查找错误


有什么方法可以实现这一点吗?

您可以将第二个参数传递给
make\u makefile
以指定不同的源目录(例如,
make\u makefile('native\u extension','lib')
),这将导致它不包括您的
native\u extension.c
文件。查看mkmf.rb的源代码,除了自己重写生成的Makefile之外,似乎没有任何方法可以使其在两个位置都显示出来。

您可以使用具有“extconf.rb”的其他文件夹中的源文件,如下所示:

+ /
|
|___ + ext
|    |
|    |___ + native_extension
|         |
|         |___ + lib
|         |    |
|         |    |___ (Source files are kept in here - may contain sub-folders)
|         |
|         |___ native_extension.c
|         |___ native_extension.h
|         |___ extconf.rb
|
|___ + lib
|    |
|    |___ (Ruby source code)
|
|___ Rakefile
require 'mkmf'

extension_name = 'native_extension'
dir_config(extension_name)

# enum all source files
$srcs = ["native_extension.c", "lib/file.c"]

# add include path to the internal folder
# $(srcdir) is a root folder, where "extconf.rb" is stored
$INCFLAGS << " -I$(srcdir)/lib"

# add folder, where compiler can search source files
$VPATH << "$(srcdir)/lib"

create_makefile(extension_name)
需要“mkmf”
扩展名='本机扩展名'
目录配置(扩展名)
#枚举所有源文件
$srcs=[“native_extension.c”,“lib/file.c”]
#将include路径添加到内部文件夹
#$(srcdir)是一个根文件夹,其中存储了“extconf.rb”
$INCFLAGS