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 9D31F7F64A for ; Fri, 8 Jan 2016 16:15:43 +0100 (CET) IronPort-PHdr: 9a23:r+AGnRXXvBZct0ZwIv95IPxs5H3V8LGtZVwlr6E/grcLSJyIuqrYZhyOt8tkgFKBZ4jH8fUM07OQ6PC+HzRYqb+681k8M7V0HycfjssXmwFySOWkMmbcaMDQUiohAc5ZX0Vk9XzoeWJcGcL5ekGA6ibqtW1aJBzzOEJPK/jvHcaK1oLsh770o8WbSj4LrQT+SIs6FA+xowTVu5teqqpZAYF19CH0pGBVcf9d32JiKAHbtR/94sCt4MwrqHwI6LoJvvRNWqTifqk+UacQTHF/azh0t/vQqALbQACTynwZW2QQ2loUUkmWpC39C7L4tiD9su81/SCGNMn1RPhgXDGr865vSxbAhyIONjp/+2bS3J9elqVe9T6ouR1zi7XUbYyJL7IqZaPQcM8BbWNFQ8MXUi1dRI6wct1cXKI6Ie9Eotyl9BM1phykCFzpWbri Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=kosmo.zb@gmail.com; spf=Pass smtp.mailfrom=kosmo.zb@gmail.com; spf=None smtp.helo=postmaster@mail-yk0-f172.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of kosmo.zb@gmail.com) identity=pra; client-ip=209.85.160.172; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kosmo.zb@gmail.com"; x-sender="kosmo.zb@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of kosmo.zb@gmail.com designates 209.85.160.172 as permitted sender) identity=mailfrom; client-ip=209.85.160.172; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kosmo.zb@gmail.com"; x-sender="kosmo.zb@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-yk0-f172.google.com) identity=helo; client-ip=209.85.160.172; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="kosmo.zb@gmail.com"; x-sender="postmaster@mail-yk0-f172.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0ADCgAx0o9Wm6ygVdFehAxtBohTo0cGkhCHBgc8EAEBAQEBAQEBEAEBAQEBBgsLCSEugi2CBwEBAQMBEhEEGQEtBgUBAwELAQUFCwMKAgIJHQICIQESAQUBChIGExIQh3gDCggOoyuBMT4xi0iEY4g0JwMKSIIuDBsBBQ5zg0SHEIJPhSSBSQWGHQyQZIVDhh2BeIFcSoxVhnGDaoInESSBFzllgVccgV0+NIVhAQEB X-IPAS-Result: A0ADCgAx0o9Wm6ygVdFehAxtBohTo0cGkhCHBgc8EAEBAQEBAQEBEAEBAQEBBgsLCSEugi2CBwEBAQMBEhEEGQEtBgUBAwELAQUFCwMKAgIJHQICIQESAQUBChIGExIQh3gDCggOoyuBMT4xi0iEY4g0JwMKSIIuDBsBBQ5zg0SHEIJPhSSBSQWGHQyQZIVDhh2BeIFcSoxVhnGDaoInESSBFzllgVccgV0+NIVhAQEB X-IronPort-AV: E=Sophos;i="5.20,539,1444687200"; d="scan'208";a="159826280" Received: from mail-yk0-f172.google.com ([209.85.160.172]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 08 Jan 2016 16:15:42 +0100 Received: by mail-yk0-f172.google.com with SMTP id k129so342580313yke.0 for ; Fri, 08 Jan 2016 07:15:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=zeUEWMdqLbg2OpJID/CTOPxngS1VcROO+pRjYhiCpkU=; b=gOQOwTLf3OWeviaSt+ESMWAYzY78zO1nrK9nvO0loBF/n0XiNsQzzS5p+8pjy/CkPO hKSx3AtHgtJIPDBCuAlJjH2bYc7QPynBKtOemYafmaYzMwXeM71mDPHBlfs9Yf+lYRmV iGY1Ago5H0JrbGyE/3eBlghV2dPEWh3YsztvmHG0zMODKqlXyvGIb0ARB6PBcwP4hx97 bAVZb5EumZTT+5vzhtXR68qh3NtTZfx6Q007qtdCkjdZAUa1tpxw9jqYpF0YF1jdum42 3ROVDAIWt4af9cckFHymSPXKxtTQxmsIWUzJ4YLaP2EYBljzCi5ZzZ88FT4Bb6TFgeh0 /kUw== MIME-Version: 1.0 X-Received: by 10.129.72.84 with SMTP id v81mr81146731ywa.101.1452266141593; Fri, 08 Jan 2016 07:15:41 -0800 (PST) Sender: kosmo.zb@gmail.com Received: by 10.129.38.10 with HTTP; Fri, 8 Jan 2016 07:15:41 -0800 (PST) In-Reply-To: <86r3hsnoox.fsf@gmail.com> References: <86r3hsnoox.fsf@gmail.com> Date: Fri, 8 Jan 2016 15:15:41 +0000 X-Google-Sender-Auth: R6Nnsw2719i08rywyv1PF1U5GS8 Message-ID: From: David Sheets To: Malcolm Matalka Cc: O Caml Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Including a C library statically in an Ocaml library 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. 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