From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id A5D507F64A for ; Fri, 8 Jan 2016 15:58:18 +0100 (CET) IronPort-PHdr: 9a23:eSkD5hYqujFsrO2m6nKXIeb/LSx+4OfEezUN459isYplN5qZpcq/bnLW6fgltlLVR4KTs6sC0LqI9fi4EUU7or+/81k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ35rxj7j60qaQSjsLrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGx48sgs/M9YUKj8Y79wDfkBVGxnYCgJ45jgvBzHCA+O/Wc0U2MMkxMODRKWwgv9W8LasjH7rfZ6wCmXJ4XETLUxVC6n5qFtAEvjiD0GLCI+6GHakOR/ia9BpBOn4RByld2HKLqJPeZzK/uONegRQnBMC4MID3RM Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=christopher@gmerlin.de; spf=None smtp.mailfrom=christopher@gmerlin.de; spf=None smtp.helo=postmaster@mout.kundenserver.de Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of christopher@gmerlin.de) identity=pra; client-ip=212.227.17.24; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christopher@gmerlin.de"; x-sender="christopher@gmerlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of christopher@gmerlin.de) identity=mailfrom; client-ip=212.227.17.24; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christopher@gmerlin.de"; x-sender="christopher@gmerlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.kundenserver.de) identity=helo; client-ip=212.227.17.24; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="christopher@gmerlin.de"; x-sender="postmaster@mout.kundenserver.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DgAACLzY9WnBgR49RehAxtiFm1Ox6FcQKBHjsRAQEBAQEBAQEQAQEBAQEGDQkJIS6CLYIIAQEDAScTPwULCyETEg8SNhmIGgMKDAEJvl4NgnYBAQEBAQEEAQEBAR+KNIEhgk+CVIQZBY05iVSFQ4YdgW9nfkqGfIVZhnGDaoNzOII9FQeBXnGFYQEBAQ X-IPAS-Result: A0DgAACLzY9WnBgR49RehAxtiFm1Ox6FcQKBHjsRAQEBAQEBAQEQAQEBAQEGDQkJIS6CLYIIAQEDAScTPwULCyETEg8SNhmIGgMKDAEJvl4NgnYBAQEBAQEEAQEBAR+KNIEhgk+CVIQZBY05iVSFQ4YdgW9nfkqGfIVZhnGDaoNzOII9FQeBXnGFYQEBAQ X-IronPort-AV: E=Sophos;i="5.20,539,1444687200"; d="scan'208";a="159823729" Received: from mout.kundenserver.de ([212.227.17.24]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jan 2016 15:58:17 +0100 Received: from mortimer.gmerlin.de ([2.246.58.67]) by mrelayeu.kundenserver.de (mreue103) with ESMTPSA (Nemesis) id 0MYtjH-1alVie30tv-00Vk5J; Fri, 08 Jan 2016 15:58:16 +0100 Date: Fri, 8 Jan 2016 15:58:13 +0100 From: Christopher Zimmermann To: caml-list@inria.fr Cc: Malcolm Matalka Message-ID: <20160108155813.118c909b@mortimer.gmerlin.de> In-Reply-To: <86r3hsnoox.fsf@gmail.com> References: <86r3hsnoox.fsf@gmail.com> X-Mailer: Claws Mail 3.13.1 (GTK+ 2.24.29; x86_64-unknown-openbsd5.9) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:imvEA4aan2NDJg5ItrRgLWHrI5NJH5t/bIifkZlKcW5CNl99rbU 3QK2idcRNWGXiXO/fmfP7dqG0g6QTUxq2lnHUScsK9WxSDXgfcfuyONfRjWxLD0kOlnT7q5 wU9tS4OX7Xm/htsFhcz9TT+8l03Cxv8Q3xYpYx7WIOb1KyQ7hLGO6DNtVJ8JLfMZPeeQcul Y9eO01C3/T4rUZc9F/fjQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:0PLgJ5ubhek=:ZWAX10vqdFl6PnUlt7RdU3 hj89JLLI+SmtVaY0/8DfBaMcWfKTQJ3SOcqCpIDWW6aWQWbe9yHNoSl4G7P1o7np5AX86AJzR yfHmcTaYQyztJyJNG7a233IH2kAbXv6t7ApvRhXmUgQQXcmZbWvg4mwK7KMiD17qak2qexUeO tpB/6asH1mpXUCLk6TX/gor+IAE++rG4lz9h4Y6dwul+VpQJDe1teSjC+ar8l/7CyOcPQZVDw DDvdd1NwblFMUH16eSna9z/MKp5MhMdiW+CM7KC6fBCNKRNWPwGekcfcSiIAokRBRxZyrpqsZ zNzr+yPP9wscud/MORqdtadBSOa64s6HHTgO81lrMHMs9yeM+Ey2LgDBO0djOi/PQOQ2CTCcu AHkwxx3xE9riuabBYjqKViUvyyxia9GHEV0Sp66LapRolK0VS3CguYAaZqaPZjRl4xNtFAKRi Ox39AuhbL8KwdQtd/4ZigrVj9ulhlI3shVLuYvgjARQ51ABRgoQa+opMTdS/NOnxTR11CgULk gKOrA7ddTpPaqO66Nj9Q/UCZvhkbpwgkZmRR2E7WBli7jQlQ6oL9TxIlR2bGGa9q/+ZbjJZm8 BRZ5Bkz7u/IvWl7E6qUMUzwLD6pSZA/4V6Frztpg3yp2gMYlCcXEVXZpvCu/sqm3SLiH2j1xA 91BfxOMUrrm6nzFZ/ZoqNXVjux00mwwR3dFHHXbTeEJBmEnnijp0+sn00AtCicAUXtT5o4Mz2 ppiiVaJbY896urGC Subject: Re: [Caml-list] Including a C library statically in an Ocaml library On Fri, 08 Jan 2016 14:14:22 +0000 Malcolm Matalka wrote: > The core problem I am having is a C library I want to bind has a > number of macros which I need the value of. Here is how I am trying > to solve it, but perhaps there is a better way: > > I have a small C library which gets compiled to libfoo.a which > provides functions that return the macro values, like: > > int macro1() { return MACRO1; } > > I then have an ocaml library, called ofoo, that uses Ctypes to bind > to macro1: > > let macro1 = foreign "macro" (void @-> returning int) > > Where I am having issues is this small library, I'd prefer it to not > have to be installed on the system but just compiled into the Ocaml > library so that a user just has to link against that library. Right > now, none of the symbols (macro1) are being included in the library, That's no surprise. Macros are evaluated at compile time. You won't see their name (only their value) in the compiled object file. > I'm guessing because the linker sees no direct use of them. And I'm > not even sure if I can get it included in the ocaml library. I'm > also not able to get the libfoo symbols linked into a final > executable, I'm guessing for similar reasons. > > What are my options here? > > If I've missed any useful information, let me know. I haven't > interoped much with C directory in Ocaml so I'm not sure what > information is important. You could hardcode the value of the macros into your ocaml code like this: let macro1 = 4096;; But I don't see anything wrong with your approach. If you have really many macros and don't want to add that many functions you could create a static record of all the macro values in your C stub code like this (not tested): value get_constants(value) { static value constants[5] = { (4 << 10), /* header for block of size 4 */ Val_long(Macro1), Val_long(Macro2), NULL, Val_long(Macro4) }; if (constants.3 == NULL) { constants.3 = caml_copy_string(Macro3); } return (constants + 1); } Christopher -- http://gmerlin.de OpenPGP: http://gmerlin.de/christopher.pub F190 D013 8F01 AA53 E080 3F3C F17F B0A1 D44E 4FEE