caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Mixed static/dynamic linking of libraries
@ 2011-05-02  6:49 Paul Steckler
  2011-05-02 12:00 ` Richard W.M. Jones
  2011-05-15 12:46 ` ygrek
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Steckler @ 2011-05-02  6:49 UTC (permalink / raw)
  To: caml-list

I want to statically link a library (libsqlite3.a) with my OCaml
application, but allow other
libraries to link dynamically. I'm building using ocamlfind on Linux.
I've tried various combinations
of -cclib -static and -cclib -Bdynamic, to no avail.  If I use the arguments

  -cclib -static -cclib -lsqlite3

the linker appears to find libsqlite3.a, but the linker then tries to
statically link every other library
used by my application.  That's so even if I follow the above by
-cclib -Bdynamic.

Is there a way to mix static and dynamic libraries using ocamlfind?

-- Paul

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Mixed static/dynamic linking of libraries
  2011-05-02  6:49 [Caml-list] Mixed static/dynamic linking of libraries Paul Steckler
@ 2011-05-02 12:00 ` Richard W.M. Jones
  2011-05-02 12:40   ` Gerd Stolpmann
  2011-05-15 12:46 ` ygrek
  1 sibling, 1 reply; 4+ messages in thread
From: Richard W.M. Jones @ 2011-05-02 12:00 UTC (permalink / raw)
  To: Paul Steckler; +Cc: caml-list

On Mon, May 02, 2011 at 04:49:03PM +1000, Paul Steckler wrote:
> I want to statically link a library (libsqlite3.a) with my OCaml
> application, but allow other
> libraries to link dynamically. I'm building using ocamlfind on Linux.
> I've tried various combinations
> of -cclib -static and -cclib -Bdynamic, to no avail.  If I use the arguments
> 
>   -cclib -static -cclib -lsqlite3
> 
> the linker appears to find libsqlite3.a, but the linker then tries to
> statically link every other library
> used by my application.  That's so even if I follow the above by
> -cclib -Bdynamic.
> 
> Is there a way to mix static and dynamic libraries using ocamlfind?

Have you tried naming the library explicitly, eg:

  -cclib /usr/lib/libsqlite3.a

Rich.

-- 
Richard Jones
Red Hat

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Mixed static/dynamic linking of libraries
  2011-05-02 12:00 ` Richard W.M. Jones
@ 2011-05-02 12:40   ` Gerd Stolpmann
  0 siblings, 0 replies; 4+ messages in thread
From: Gerd Stolpmann @ 2011-05-02 12:40 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: Paul Steckler, caml-list

Am Montag, den 02.05.2011, 13:00 +0100 schrieb Richard W.M. Jones:
> On Mon, May 02, 2011 at 04:49:03PM +1000, Paul Steckler wrote:
> > I want to statically link a library (libsqlite3.a) with my OCaml
> > application, but allow other
> > libraries to link dynamically. I'm building using ocamlfind on Linux.
> > I've tried various combinations
> > of -cclib -static and -cclib -Bdynamic, to no avail.  If I use the arguments
> > 
> >   -cclib -static -cclib -lsqlite3
> > 
> > the linker appears to find libsqlite3.a, but the linker then tries to
> > statically link every other library
> > used by my application.  That's so even if I follow the above by
> > -cclib -Bdynamic.
> > 
> > Is there a way to mix static and dynamic libraries using ocamlfind?
> 
> Have you tried naming the library explicitly, eg:
> 
>   -cclib /usr/lib/libsqlite3.a

You could also try

	-cclib -l:libsqlite3.a

According to ld docs, the colon prevents the automatic name translation
that results in preferring libsqlite3.so.

However, I don't think this will be successful. The
ocamlfind/ocamlopt/gcc/ld chain will generate a normal -lsqlite3
nevertheless, and so far I've tried it, this takes precedence. What you
can try is to copy libsqlite3.a to a private directory p, and use -ccopt
-Lp to add it to the library search path.

Also note that static linking is more sensitive to the order of the
linked libraries. As more or less everybody is using dynamic linking,
these problem often remain unnoticed.

Gerd


> Rich.
> 
> -- 
> Richard Jones
> Red Hat
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] Mixed static/dynamic linking of libraries
  2011-05-02  6:49 [Caml-list] Mixed static/dynamic linking of libraries Paul Steckler
  2011-05-02 12:00 ` Richard W.M. Jones
@ 2011-05-15 12:46 ` ygrek
  1 sibling, 0 replies; 4+ messages in thread
From: ygrek @ 2011-05-15 12:46 UTC (permalink / raw)
  To: Paul Steckler; +Cc: caml-list

On Mon, 2 May 2011 16:49:03 +1000
Paul Steckler <steck@stecksoft.com> wrote:

> I want to statically link a library (libsqlite3.a) with my OCaml
> application, but allow other
> libraries to link dynamically. I'm building using ocamlfind on Linux.

The ultimate goal is to get `-Wl,-Bstatic -lsqlite3 -Wl,-Bdynamic` in the
final invocation of gcc when linking your binary (without any other references to
sqlite3 on command-line).

Possible approaches :
1) patch the build system of ocaml-sqlite3 so that it embeds the above flags into cmxa
2) insert linker instructions with -ccopt's around the reference to sqlite3.cmxa when linking your application - IIRC this
didn't work for me because ocamlopt reorders command-line arguments when passing them to gcc in some incomprehensible way.
3) use -noautolink and specify the above flags as single -ccopt (and do this for all cma's with embedded options).

(1) looks most simple to me and ideally ocamlopt could allow embedding several sets of options into cma and choosing
them at final link with some option/tags, then all libraries could easily embed two command-lines - for static and dynamic linking.

-- 
 ygrek
 http://ygrek.org.ua

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-05-15 12:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-02  6:49 [Caml-list] Mixed static/dynamic linking of libraries Paul Steckler
2011-05-02 12:00 ` Richard W.M. Jones
2011-05-02 12:40   ` Gerd Stolpmann
2011-05-15 12:46 ` ygrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).