caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* How to add a "non-standard" static c library to ocaml project
@ 2009-12-29 15:55 lin hong
  2009-12-29 16:10 ` [Caml-list] " Mark Shinwell
  0 siblings, 1 reply; 2+ messages in thread
From: lin hong @ 2009-12-29 15:55 UTC (permalink / raw)
  To: caml-list



Hey,

I'm struggling with this for few days.

We have a static C library, instead of "libsomename.a", it's "somename.a",
so we could not link it in the usually way like "-lsomename".
In myocamlbuild.ml, I did try to add it's head files dir into cflags, and
"/somelib/dir/somename.a" to clibs. This works for Mac, however, in Linux,
it won't pass the linking process.

Any idea is appreciated ~

Thank you.
Lin








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

* Re: [Caml-list] How to add a "non-standard" static c library to ocaml project
  2009-12-29 15:55 How to add a "non-standard" static c library to ocaml project lin hong
@ 2009-12-29 16:10 ` Mark Shinwell
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Shinwell @ 2009-12-29 16:10 UTC (permalink / raw)
  To: lin hong; +Cc: caml-list

On Tue, Dec 29, 2009 at 10:55:49AM -0500, lin hong wrote:
> I'm struggling with this for few days.
> 
> We have a static C library, instead of "libsomename.a", it's "somename.a",
> so we could not link it in the usually way like "-lsomename".
> In myocamlbuild.ml, I did try to add it's head files dir into cflags, and
> "/somelib/dir/somename.a" to clibs. This works for Mac, however, in Linux,
> it won't pass the linking process.

I suspect this is because the order of arguments on the linker command line is
wrong.  I think it is the case that when using the GNU linker, and object file
foo.o has unresolved symbols that are to be found in static library bar.a, that
you have to specify foo.o on the command line before bar.a.  (This means you
may have to specify a static library multiple times.)  However it looks like
Mac OS X is different.  Reading the manual page for ld on Mac OS X says:

  "Unlike traditional linkers, ld will continually search a static library
  while linking. There is no need to specify a static library multiple times
  on the command line."

which is maybe why your link is working on the Mac -- even if you haven't
specified the .a multiple times, perhaps it is going back and re-examining
the static library when it encounters the object later on the command line.

You shouldn't have to specify the full path to the static library; at least
on a system using the GNU linker you should be able to use something like:

        -static -lsomename -dynamic

in the middle of the command.

Just as a side point, an output of the linker errors pasted into an email
is always useful for this sort of diagnosis.

Hope that helps,
Mark


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

end of thread, other threads:[~2009-12-29 16:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-29 15:55 How to add a "non-standard" static c library to ocaml project lin hong
2009-12-29 16:10 ` [Caml-list] " Mark Shinwell

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).