From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 9FE2D7F64A for ; Fri, 8 Jan 2016 16:19:34 +0100 (CET) IronPort-PHdr: 9a23:vnA9HBbCfYjGyVVBnxmUN+H/LSx+4OfEezUN459isYplN5qZpcSzbnLW6fgltlLVR4KTs6sC0LqI9fi4EUU7or+/81k6OKRWUBEEjchE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZvIaytQ8iJ35rxj7j60qaQSjsLrQL1Wal1IhSyoFeZnegtqqwmFJwMzADUqGBDYeVcyDAgD1uSmxHh+pX4p8Y7oGx48sgs/M9YUKj8Y79wDfkBVGxnYFYO+dbzuBLfYQyK73oaGiVKw1sbSzTCuT3zQJb9+hD6u+dhw2HOJs37QKwvcT2m8qItTR70zioLKmhq3nvQj5lVhaZQpxak7zl234fQY4jdYP97d7/UedATbWVEV8dVESdGB9XvPMM0E+MdMLMA/MHGrFwUoE77WFCh Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=mmatalka@gmail.com; spf=Pass smtp.mailfrom=mmatalka@gmail.com; spf=None smtp.helo=postmaster@mail-wm0-f46.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of mmatalka@gmail.com) identity=pra; client-ip=74.125.82.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of mmatalka@gmail.com designates 74.125.82.46 as permitted sender) identity=mailfrom; client-ip=74.125.82.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="mmatalka@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-wm0-f46.google.com) identity=helo; client-ip=74.125.82.46; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="mmatalka@gmail.com"; x-sender="postmaster@mail-wm0-f46.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DqAADo0o9Wmy5SfUpeDoN+bYhZo0eRdCKFbQKBHjwQAQEBAQEBAQEQAQEBAQEGCwsJIS6CLYIHAQEBAwESFRkBGxIGBQEDAQsGBQsNCQQhDwEEDQIRAQUBChgTEhCHdwEDCggECqMtgTE+MY0ygnmIEQoZJwMKV4IfAQEBAQEBAQECAQEBAQEBAQEVAQUOhDeCEYR/gk+GbQWGHQyQZIVDhh2BeIFcSoZyhWOGcYNqgic1gRc5gi8NFQeBHz5yhWEBAQE X-IPAS-Result: A0DqAADo0o9Wmy5SfUpeDoN+bYhZo0eRdCKFbQKBHjwQAQEBAQEBAQEQAQEBAQEGCwsJIS6CLYIHAQEBAwESFRkBGxIGBQEDAQsGBQsNCQQhDwEEDQIRAQUBChgTEhCHdwEDCggECqMtgTE+MY0ygnmIEQoZJwMKV4IfAQEBAQEBAQECAQEBAQEBAQEVAQUOhDeCEYR/gk+GbQWGHQyQZIVDhh2BeIFcSoZyhWOGcYNqgic1gRc5gi8NFQeBHz5yhWEBAQE X-IronPort-AV: E=Sophos;i="5.20,539,1444687200"; d="scan'208";a="196308078" Received: from mail-wm0-f46.google.com ([74.125.82.46]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 08 Jan 2016 16:19:33 +0100 Received: by mail-wm0-f46.google.com with SMTP id u188so140821443wmu.1 for ; Fri, 08 Jan 2016 07:19:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=IVto3Bm/MoISoc0tU9u+EqUY6sI2Z5tKnGGaz9YBeCs=; b=pU5HuLbit4f35j5/CUAbU4QZda4VPZJdNrhHyESuvDOx2gc4BpqVjpS+Sv5GXUfmWr Smkmk56KBCexPj2yMWzx5dzdajc6O8RkMuXOssWdQpszOi8/Vhe61IHHQB7V3Kvw9Sc7 fWCB4GbJ6+HaHjh2li5xObmQHFy4XPjB1ETDDDIijob76el5DDoCjMQCXt1rl9F9ms3b 7bgCTC34WIVIH+9ZLno/diSES/n/xGJnUBzSdO8awF/vbaWM0hnydpMSGn2Z5Qe37WFl XCbzzwIl6/hNVgcLE8j4YbPgozK0bSSmPWTdIe80Sz6zNwYfYGWQXF1fwEOZ1rP9O3Kf omSA== X-Received: by 10.28.24.85 with SMTP id 82mr24598364wmy.58.1452266373076; Fri, 08 Jan 2016 07:19:33 -0800 (PST) Received: from localhost (li195-236.members.linode.com. [178.79.139.236]) by smtp.gmail.com with ESMTPSA id ka4sm6814133wjc.47.2016.01.08.07.19.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Jan 2016 07:19:31 -0800 (PST) From: Malcolm Matalka To: David Sheets Cc: O Caml References: <86r3hsnoox.fsf@gmail.com> Date: Fri, 08 Jan 2016 15:19:28 +0000 In-Reply-To: (David Sheets's message of "Fri, 8 Jan 2016 15:15:41 +0000") Message-ID: <86egdsnlof.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] Including a C library statically in an Ocaml library David Sheets writes: > On Fri, Jan 8, 2016 at 2:14 PM, 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, 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? > > I'd recommend using ctypes 0.4+ stub generation support which can bind > macro values and detect struct layout at an early compilation stage. > You can see it in use to do this in my ocaml-unix-errno library > . One benefit with this > approach is greater static checking and c <-> ocaml type safety. > > If you continue using dynamic bindings, two lonker flags may be of use to you: > > --no-as-needed : on recent Ubuntu distributions, gcc automatically > includes the --as-needed flag which drops symbols that are not > referenced. Unfortunately, clang does not understand this flag so you > need to have a conditional in your build system to detect the compiler > in use if you want a cross-platform library. > > -E : The Exports local symbols which are statically linked into a > binary into the dynamic symbol table so that they can be found with > dlsym. > > You can use these with gcc like -Wl,-E for example. Will these approaches require that I have the C library installed to compile against any binary using my library or will the symbols be part of the ocaml library? In my current version I have a libfoo.a that gets created in the project and then linked against the library. > > Hope this helps, > > David Sheets > > >> 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. >> >> /Malcolm >> >> -- >> Caml-list mailing list. Subscription management and archives: >> https://sympa.inria.fr/sympa/arc/caml-list >> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners >> Bug reports: http://caml.inria.fr/bin/caml-bugs