mattn/mruby-require

Error when compiling: "Don't know how to build task 'some/path/mruby-2.1.1/build/host/mrbgems/mruby-array-ext/src/array.o'" and "relocation R_X86_64_PC32 against symbol `mrb_ary_push' can not be used when making a shared object"

boatrite opened this issue · 0 comments

mruby 2.1.1

Summary

I ran into this when trying to add the mruby-require gem. The error I get depends on the order I do stuff in.

To reproduce the first, I run rake clean, add the mruby-require gem to the build config (if not there), and try to compile.

Relevant-looking output:

      MRBC test/t/literals.rb                                                                                                                                                                                     
      MRBC test/t/object.rb                                                                                                                                                                                       
      MRBC test/t/iterations.rb                                                                                                                                                                                   
CC    build/test/mrbgems/mruby-test/gem_test.c -> build/test/mrbgems/mruby-test/gem_test.o                                                                                                                        
CC    mrbgems/mruby-error/test/exception.c -> build/test/mrbgems/mruby-error/test/exception.o                                                                                                                     
      MRBC mrbgems/mruby-error/test/exception.rb                                                                                                                                                                  
CC    build/test/mrbgems/mruby-error/gem_test.c -> build/test/mrbgems/mruby-error/gem_test.o                                                                                                                      
AR    build/test/mrbgems/mruby-test/mrbtest.a                                                                                                                                                                     
ar: creating some/path/mruby-2.1.1/build/test/mrbgems/mruby-test/mrbtest.a                                                                                                                        
LD    build/test/bin/mrbtest                                                                                                                                                                                      
                                                                                                                                                                                                                  
Build summary:                                                                                                                                                                                                    
                                                                                                                                                                                                                  
================================================                                                                                                                                                                  
      Config Name: host                                                                                                                                                                                           
 Output Directory: build/host                                                                                                                                                                                     
         Binaries: mrbc                                                                                                                                                                                           
    Included Gems:                                                                                                                                                                                                
             mruby-require                                                                                                                                                                                        
             mruby-compiler - mruby compiler library                                                                                                                                                              
             mruby-bin-mrbc - mruby compiler executable                                                                                                                                                           
================================================                                                                                                                                                                  
                                                                                                                                                                                                                  
rake aborted!                                                                                                                                                                                                     
Don't know how to build task 'some/path/mruby-2.1.1/build/host/mrbgems/mruby-array-ext/src/array.o' (See the list of available tasks with `rake --tasks`)                                         

To reproduce the latter, I run rake clean, compile with no gems, add the mruby-require gem to my build config, and try to compile again.

<...>
      MRBC test/t/literals.rb 
      MRBC test/t/object.rb 
      MRBC test/t/iterations.rb 
CC    build/test/mrbgems/mruby-test/gem_test.c -> build/test/mrbgems/mruby-test/gem_test.o
CC    mrbgems/mruby-error/test/exception.c -> build/test/mrbgems/mruby-error/test/exception.o
      MRBC mrbgems/mruby-error/test/exception.rb 
CC    build/test/mrbgems/mruby-error/gem_test.c -> build/test/mrbgems/mruby-error/gem_test.o
AR    build/test/mrbgems/mruby-test/mrbtest.a 
LD    build/test/bin/mrbtest 

Build summary:

================================================
      Config Name: host
 Output Directory: build/host
         Binaries: mrbc
    Included Gems:
             mruby-require
             mruby-compiler - mruby compiler library
             mruby-bin-mrbc - mruby compiler executable
================================================

LD    some/path/mruby-2.1.1/build/host/lib/mruby-array-ext.so 
/usr/bin/ld: some/path/mruby-2.1.1/build/host/lib/libmruby.a(array.o): relocation R_X86_64_PC32 against symbol `mrb_ary_push' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
rake aborted!
Command failed with status (1): [gcc -shared -fPIC -o "some/path...]

Fix

The relevant bits are that "To work properly, mruby-require must be the last mrbgem specified in the build configuration. Any mrbgem specified after mruby-require is compiled as a shared object" (as per the README, which explains the errors above) and that the default build config includes this line conf.gembox 'default' which adds a bunch of default gems (these would be the gems that the above errors are complaining about)

Make sure that your conf.gem github: 'mattn/mruby-require' line is below the conf.gembox 'default' line.

It's easy to make this mistake because the default build_config.rb has the "Use mrbgems" section above the "include the default GEMs" section.

After I made that fix, it compiled without issue. Will close since this is really just here to hopefully save some other people some time in the future.