How did I call gcc to create .bundle instead of .so?

I am trying to write a Ruby extension and I have successfully compiled my shared nmatrix.so object nmatrix.so all day. But then, all of a sudden, it starts producing nmatrix.bundle instead without any .so file at all.

This does not give me any linker errors, so I cannot imagine why this would be. I also did not change anything in my Makefile or extconf.rb . I constantly used Ruby 1.9.3p0 through rvm.

I tried to do git stash save with my work during the day, and compiling something I know should work without linker errors (something that created .so) before. Unfortunately, this also creates a .bundle file.

Obviously, I did something - maybe I accidentally installed something that changed some of the critical GCC settings. This is entirely possible, since most of the day I spent trying to create LAPACK and ATLAS, and also installed homebrew at some point.

I found that there is a workaround. I am changing these two lines:

 DLLIB = $(TARGET).bundle # ... LDSHARED = $(CC) -dynamic -bundle 

to

 DLLIB = $(TARGET).so # ... LDSHARED = $(CC) -dynamic 

And then the library compiles and loads correctly. However, I don’t have the slightest change that I changed in extconf.rb (or elsewhere), which would cause this Makefile to be automatically created with .bundle files instead of .so .

Question: how exactly did I cause this, and what should I do to restore it?

+6
source share
2 answers

The problem seems to be related to using LLVM gcc, which works poorly with Xcode 4.2.

I have regular gcc, so I reinstall Ruby as follows:

 export CC=/usr/bin/gcc-4.2 rvm install 1.9.3 

Most directions seem to use rvm install 1.9.3 --enable-shared instead, but this additional flag seems to be the source of the problem.

In any case, it seems that now I can upload .bundle files.

+2
source

The C Extension The RubyGems Handbook provides an overview of the build process.

The critical lines in your extconf.rb are near the ends:

 require "mkmf" # ... create_makefile("nmatrix") 

This will create a Makefile for you. Makefile is created using the configuration values ​​stored in the RbConfig::CONFIG[] array; RbConfig::CONFIG['DLEXT'] configuration value of interest to you:

 $ ruby -e "require 'rbconfig'; puts RbConfig::CONFIG['DLEXT'];" so 

To easily see the entire configuration, find the rbconfig.rb file; mine is in /usr/lib/ruby/1.8/x86_64-linux/rbconfig.rb and I will include the first few lines:

 # This file was created by mkconfig.rb when ruby was built. Any # changes made to this file will be lost the next time ruby is built. module Config RUBY_VERSION == "1.8.7" or raise "ruby lib version (1.8.7) doesn't match executable version (#{RUBY_VERSION})" TOPDIR = File.dirname(__FILE__).chomp!("/lib/ruby/1.8/x86_64-linux") DESTDIR = '' unless defined? DESTDIR CONFIG = {} CONFIG["DESTDIR"] = DESTDIR CONFIG["INSTALL"] = '/usr/bin/install -c' CONFIG["EXEEXT"] = "" CONFIG["prefix"] = (TOPDIR || DESTDIR + "/usr") ... CONFIG["DLEXT"] = "so" CONFIG["LDSHARED"] = "$(CC) -shared" CONFIG["CCDLFLAGS"] = " -fPIC" ... 

So, some version of your rbconfig.rb file was created when another version of Ruby was built, which suggested that dynamically linked extensions should have a different extension. This may be a feature of rvm (which I still need to learn more about), or it may be the difference between the supplied Apple Ruby and the self-compiled Ruby. You can see in the comment header of the file that you can easily make changes to rbconfig.rb yourself, but it will be deleted the next time you restore or install another Ruby built.

(By the way, I thought the extension was .dylib , but some time passed since I used OS X too).

+3
source

Source: https://habr.com/ru/post/905779/


All Articles