mkmf ignores files in sub-folders when it compiles the C extension

后端 未结 2 1562

I\'d like to organize the C source code like this:

+ /
|
|___ + ext
|    |
|    |___ + native_extension
|         |
|         |___ + lib
|         |    |
|           


        
2条回答
  •  不知归路
    2021-01-05 19:56

    You can use source files from another folders with "extconf.rb" like this:

    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)
    

提交回复
热议问题