Mkmf ignores files in subfolders when compiling the C extension

I would like to organize the C source code as follows:

+ / | |___ + 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 

I had a problem with this installation working correctly using mkmf . Files in native_extension/lib that are included by native_extension.c are completely ignored.

When I create the extension, only native_extension.{h,c} compiles and I get incomplete native_extension.{so,dll} , which gives me character search errors when I try to run it.

How to make this work?

+4
source share
2 answers

For now, you can pass the second make_makefile argument to specify a different source directory (e.g. make_makfile('native_extension', 'lib') ), which will not include your native_extension.c file. Looking at the source for mkmf.rb, it does not appear there to make it look in both places without overwriting the created Makefile itself.

+3
source

You can use the source files from other folders using "extconf.rb" as follows:

 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) 
+2
source

All Articles