1

Problem

I have an intuitive understanding of the difference between dynamic and static libraries. That said, I'm trying to write a C Extension that makes use of a third party library. I have compiled this library both statically and dynamically and I refference the static library in my extconf.rb. For clarity...

A = 3rd party dynamic library (Theoretically unused)
B = 3rd party static library (refferenced in extconf.rb)
C = Ruby C extension

Here is the thing: When I require C in my ruby code I get an error. This error is not thrown if A is in the present working directory. Wierd. Having B in the present working directory seems to confuse ruby and it can't find A.

Ideally I want to not have B present on the system at all. I would like to have it all hidden away in C. That is what I thought a static library did. Is this possible and if so how is it done?

Contexet

Windows7, Ruby2.0, DevKit, MinGW. 3rd party library is CGAL which in turn relies on boost, mpfr and gmp. The extension is intended for use with SketchUp's ruby API. SketchUp ruby extensions are installed through the SketchUp interface which just copies the relevant files to a directory of it's choice and loads them. My extconf looks as follows:

#extconf.rb
require 'mkmf'

dir_config("CGAL", "C:/CGAL-4.2/include", "C:/CGAL-4.2/bin")
have_library("CGAL")
dir_config("boost", "C:/boost/boost_1_54_0", "C:/boost/boost_1_54_0/stage/lib")
have_library("boost_thread-mgw47-mt-1_54")
have_library("boost_system-mgw47-mt-1_54")
dir_config("gmp", "C:/CGAL-4.2/auxiliary/gmp")


create_makefile( 'HW' )

require() failing

When libCGAL.dll is not found I get the following output. Putting it in the present working directory fixes this.

test.rb:2:in `require_relative': 126: No se puede encontrar el módulo especificado.   - 
C:/Users/Noel/code/tru-offset/HW.so (LoadError)from test.rb:2:in `<main>'
noelwarr
  • 117
  • 7
  • Any reason you cannot simply copy in the library's `.c` and `.h` and make it an integral part of the extension? These would be needed if you ever deployed somewhere else anyway (or you'd need a separate `rake` task to do much the same to move around and create the pre-compiled static lib). – Neil Slater Oct 09 '13 at 11:26
  • Could you give details: The error message. Are you creating a gem or some other project (if a gem, did you create using `bundle gem`). Relevant contents of `extconf.rb`. How you are invoking the compiler (via a `rake-compile` task - if so please share code)? – Neil Slater Oct 09 '13 at 11:30
  • Edited question to include more information as requested. Copying the library's .c and .h files seems like opening pandora's box to me. Is it really that simple? Remember this library relies on other libraries like Boost and GMP – noelwarr Oct 09 '13 at 13:38
  • It's beyond me, except to quickly check you saw section 7.2 here, and followed instructions for static-linkable libraries via cmake: http://www.cgal.org/Manual/latest/doc_html/installation_manual/Chapter_installation_manual.html ? – Neil Slater Oct 09 '13 at 14:11

0 Answers0