Version française
Home     About     Download     Resources     Contact us    
Browse thread
How to add a "non-standard" static c library to ocaml project
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mark Shinwell <mshinwell@j...>
Subject: Re: [Caml-list] How to add a "non-standard" static c library to ocaml project
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