From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q3QA8Eea024954 for ; Thu, 26 Apr 2012 12:08:14 +0200 X-IronPort-AV: E=Sophos;i="4.75,485,1330902000"; d="scan'208";a="141687933" Received: from montgallet.polytechnique.fr (HELO MacBook-Pro-de-Xavier-ALLAMIGEON.local) ([129.104.4.248]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-CAMELLIA256-SHA; 26 Apr 2012 12:08:09 +0200 Message-ID: <4F991E88.5060402@inria.fr> Date: Thu, 26 Apr 2012 12:08:08 +0200 From: Xavier ALLAMIGEON User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: caml-list@inria.fr References: <4F99003B.9070001@inria.fr> <4F990869.5050105@etorok.net> In-Reply-To: <4F990869.5050105@etorok.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] static C library of wrappers: compilation issues Dear Edwin, Le 26/04/12 10:33, Török Edwin a écrit : >> Here's the way I'm compiling everything. It builds a libhello_world.a static library from ml_code.obj.o and c_code.o. >> ocamlc -c ml_code.mli >> ocamlopt -c ml_code.ml >> ocamlopt -output-obj ml_code.cmx -o ml_code.obj.o >> gcc -c c_code.c -I"`ocamlc -where`" >> ar rcs libhello_world.a ml_code.obj.o c_code.o >> gcc -o test -L. -L"`ocamlc -where`" test.c -lhello_world -lasmrun -lm -ldl > > You need -Wl,--whole-archive -Wl,--no-whole-archive around the link of your .a, like this: > gcc -o test -L. -L"`ocamlc -where`" test.c -Wl,--whole-archive -lhello_world -Wl,--no-whole-archive -lasmrun -lm -ldl Thanks a lot, it works now! > Otherwise the functions from your .a are dropped because nothing else before it needs it (-lasmrun would, but its after your .a). What do you mean exactly? I imagine that test.o needs some functions of the libhello_world.a. But I don't see why libasmrun would need some other functions of libhello_world... What about the following alternative where libasmrun is directly appended to the .a file? cp "`ocamlc -where`"/libasmrun.a libhello_world.a ar rcs libhello_world.a ml_code.obj.o c_code.o gcc -o test -L. -L"`ocamlc -where`" test.c -lhello_world -lm -ldl Best regards. Xavier