Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #2708 > unrolled thread
| Started by | Alex Young <alex@blackkettle.org> |
|---|---|
| First post | 2011-04-12 15:21 -0500 |
| Last post | 2011-04-14 00:38 -0500 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.ruby
Building extensions into static libraries Alex Young <alex@blackkettle.org> - 2011-04-12 15:21 -0500
Re: Building extensions into static libraries Luis Lavena <luislavena@gmail.com> - 2011-04-12 13:34 -0700
Re: Building extensions into static libraries Alex Young <alex@blackkettle.org> - 2011-04-13 10:20 -0500
Re: Building extensions into static libraries Luis Lavena <luislavena@gmail.com> - 2011-04-13 14:54 -0700
Re: Building extensions into static libraries Alex Young <alex@blackkettle.org> - 2011-04-14 00:38 -0500
| From | Alex Young <alex@blackkettle.org> |
|---|---|
| Date | 2011-04-12 15:21 -0500 |
| Subject | Building extensions into static libraries |
| Message-ID | <d91d62db0fd3fffefa35dd68d23c2939@ruby-forum.com> |
I am delving into the wonder that is mkmf.rb. I'm trying to tell extconf.rb that I want to build an extension into a static library, but I can't see how to tell it to generate the static target in the Makefile. Has anyone else tried this? -- Alex -- Posted via http://www.ruby-forum.com/.
[toc] | [next] | [standalone]
| From | Luis Lavena <luislavena@gmail.com> |
|---|---|
| Date | 2011-04-12 13:34 -0700 |
| Message-ID | <e7d092f7-8ede-40d2-9cdf-4d556af6a729@17g2000prr.googlegroups.com> |
| In reply to | #2708 |
On Apr 12, 5:21 pm, Alex Young <a...@blackkettle.org> wrote: > I am delving into the wonder that is mkmf.rb. I'm trying to tell > extconf.rb that I want to build an extension into a static library, but > I can't see how to tell it to generate the static target in the > Makefile. Has anyone else tried this? So you want to statically link against the Ruby library? In that way it will not depend on the libruby shared library? If that is the case, then --enable-static option that you can supply your extconf.rb will already do that for you. mkmf will handle that automatically for you. HTH, -- Luis Lavena
[toc] | [prev] | [next] | [standalone]
| From | Alex Young <alex@blackkettle.org> |
|---|---|
| Date | 2011-04-13 10:20 -0500 |
| Message-ID | <f59d2b5fa81e0f30c120e6895341fb14@ruby-forum.com> |
| In reply to | #2711 |
Luis Lavena wrote in post #992376: > On Apr 12, 5:21pm, Alex Young <a...@blackkettle.org> wrote: >> I am delving into the wonder that is mkmf.rb. I'm trying to tell >> extconf.rb that I want to build an extension into a static library, but >> I can't see how to tell it to generate the static target in the >> Makefile. Has anyone else tried this? > > So you want to statically link against the Ruby library? > > In that way it will not depend on the libruby shared library? > > If that is the case, then --enable-static option that you can supply > your extconf.rb will already do that for you. > > mkmf will handle that automatically for you. That doesn't seem to be doing what I'm after: $ gem unpack mongrel Unpacked gem: '/home/zander/projects/scratch/mongrel/mongrel-1.1.5' $ cd mongrel-1.1.5 $ ruby ext/http11/extconf.rb --enable-static checking for main() in -lc... yes creating Makefile $ grep -i static Makefile LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static EXTSTATIC = STATIC_LIB = static: $(STATIC_LIB) I'm expecting there to be *something* present for STATIC_LIB, which I want to give me a .a rather than a .so. To be perfectly clear, I simply don't know if what I'm trying to do here is actually possible, but neither do I know where else to look. -- Alex -- Posted via http://www.ruby-forum.com/.
[toc] | [prev] | [next] | [standalone]
| From | Luis Lavena <luislavena@gmail.com> |
|---|---|
| Date | 2011-04-13 14:54 -0700 |
| Message-ID | <6d526e35-4803-4f52-a289-99b5503da3be@t13g2000vbo.googlegroups.com> |
| In reply to | #2770 |
On Apr 13, 12:20 pm, Alex Young <a...@blackkettle.org> wrote:
>
> That doesn't seem to be doing what I'm after:
>
> $ gem unpack mongrel
> Unpacked gem: '/home/zander/projects/scratch/mongrel/mongrel-1.1.5'
>
> $ cd mongrel-1.1.5
> $ ruby ext/http11/extconf.rb --enable-static
> checking for main() in -lc... yes
> creating Makefile
>
> $ grep -i static Makefile
> LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
> LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
> EXTSTATIC =
> STATIC_LIB =
> static: $(STATIC_LIB)
>
> I'm expecting there to be *something* present for STATIC_LIB, which I
> want to give me a .a rather than a .so. To be perfectly clear, I simply
> don't know if what I'm trying to do here is actually possible, but
> neither do I know where else to look.
>
That that is why I asked what you're targeting/aiming at.
If you want to generate an static library of your extension, then you
can't rely on mkmf.
mkmf is aimed to generated shared libraries to be loaded by Ruby.
For that to work you will need to create a Makefile (or adapt the one
generated by mkmf) to generate a static library.
As long one of the symbols is exported, you can generate a static
library, take this example:
/* mylib.c */
#include <stdio.h>
extern void foo();
void foo()
{
printf("foo, exported\n");
}
In the command line:
$ gcc -c mylib.c -o mylib.o
$ ar rcs libmylib.a mylib.o
Above generates me a static library of mylib, you can check with nm
the symbols contained in there
$ gcc -shared mylib.o -o mylib.dll
That will generate a dynamic library using the compiled symbols.
Does that help?
--
Luis Lavena
[toc] | [prev] | [next] | [standalone]
| From | Alex Young <alex@blackkettle.org> |
|---|---|
| Date | 2011-04-14 00:38 -0500 |
| Message-ID | <cb19108d9016e8c90b496f19d035347c@ruby-forum.com> |
| In reply to | #2792 |
Luis Lavena wrote in post #992613:
> On Apr 13, 12:20pm, Alex Young <a...@blackkettle.org> wrote:
>>
>> neither do I know where else to look.
>>
>
> That that is why I asked what you're targeting/aiming at.
>
> If you want to generate an static library of your extension, then you
> can't rely on mkmf.
>
> mkmf is aimed to generated shared libraries to be loaded by Ruby.
>
Ok, some more details: I'm trying to embed a ruby interpreter into a
static-linked binary, along with some additional binary extensions from
rubygems. This works for the extensions in stdlib, whose Makefiles get
a STATIC_LIB entry of $(TARGET).a thanks to mkmf.rb. I don't see how,
though. The top-level Makefile following a ./configure in the ruby
source tree contains this:
EXTCONF = extconf.rb
..
extconf:
$(MINIRUBY) -run -e mkdir -- -p "$(EXTCONFDIR)"
$(RUNRUBY) -C "$(EXTCONFDIR)" $(EXTCONF) $(EXTCONFARGS)
I can't see where EXTCONFARGS is set, or I'd just copy that. I don't
see any obvious settings in the existing extconf.rb files either.
> For that to work you will need to create a Makefile (or adapt the one
> generated by mkmf) to generate a static library.
Going by the stdlib extensions, I don't think that's the case, but you'd
know better than me.
<snip>
> $ gcc -c mylib.c -o mylib.o
>
> $ ar rcs libmylib.a mylib.o
I might be able to get away with sidestepping the extensions' Makefiles
and
just do a
$ find ext/ -name "*.o" | xargs ar rcs libwhatsit.a
but I imagine that would break horribly for reasons I haven't thought
of.
--
Alex
--
Posted via http://www.ruby-forum.com/.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.ruby
csiph-web