From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr 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 9B1D9801CD for ; Tue, 29 Aug 2017 15:31:29 +0200 (CEST) Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=aziem@chawdhary.co.uk; spf=Neutral smtp.mailfrom=aziem@chawdhary.co.uk; spf=None smtp.helo=postmaster@mail-wm0-f53.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of aziem@chawdhary.co.uk) identity=pra; client-ip=74.125.82.53; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="aziem@chawdhary.co.uk"; x-sender="aziem@chawdhary.co.uk"; x-conformance=sidf_compatible Received-SPF: Neutral (mail2-smtp-roc.national.inria.fr: domain of aziem@chawdhary.co.uk does not assert whether or not 74.125.82.53 is permitted sender) identity=mailfrom; client-ip=74.125.82.53; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="aziem@chawdhary.co.uk"; x-sender="aziem@chawdhary.co.uk"; 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-f53.google.com) identity=helo; client-ip=74.125.82.53; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="aziem@chawdhary.co.uk"; x-sender="postmaster@mail-wm0-f53.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3A0UKLyhZPyhdRmVTbLQkJhAX/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZpc2+bnLW6fgltlLVR4KTs6sC0LWG9f24EUU7or+/81k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i76xXcoFx7+LQt4?= =?us-ascii?q?IPjuUs6X1pzvlrP6x5qGQAhOgjehYftbIByz5SDQss0bm8M2Kas3zBbVonJEcu?= =?us-ascii?q?FTxGdsKEi7kBP158P295lmpXd+ofUkoudSUKj/N484RKNUDD08Iihh7d/quBzr?= =?us-ascii?q?RguG+XccW38H1BFPRRXGukKpFqztuzf347IukBKROtf7GPVtAWyv?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0AeAQBTa6VZhjVSfUpeGwEBAQMBAQEJA?= =?us-ascii?q?QEBFQEBAQECAQEBAQgBAQEBhBOBFY8IjyeBcXeHQo18gSUDXCyFGwKEEEMUAQE?= =?us-ascii?q?BAQEBAQEBAQESAQEBCAsLCCgvgjMFAR4BBYI7AQEBAQIBQAEBNwEECwsYCSUPA?= =?us-ascii?q?RETAQUBHAYTihkDDQgQpAtAiyCDEoMIAQEFhCgNhBsBAQEBAQEEAQEBARwICQE?= =?us-ascii?q?IgxiBMlCDMYJzNYJXgWsBEgGGE4laJYcpgWeNIjyHWYd9hWiBIFqIVTWGdYxMi?= =?us-ascii?q?C00gRU2gSMLUzUESYJPgjofgXR1AYhuX4FTAQEB?= X-IPAS-Result: =?us-ascii?q?A0AeAQBTa6VZhjVSfUpeGwEBAQMBAQEJAQEBFQEBAQECAQE?= =?us-ascii?q?BAQgBAQEBhBOBFY8IjyeBcXeHQo18gSUDXCyFGwKEEEMUAQEBAQEBAQEBAQESA?= =?us-ascii?q?QEBCAsLCCgvgjMFAR4BBYI7AQEBAQIBQAEBNwEECwsYCSUPARETAQUBHAYTihk?= =?us-ascii?q?DDQgQpAtAiyCDEoMIAQEFhCgNhBsBAQEBAQEEAQEBARwICQEIgxiBMlCDMYJzN?= =?us-ascii?q?YJXgWsBEgGGE4laJYcpgWeNIjyHWYd9hWiBIFqIVTWGdYxMiC00gRU2gSMLUzU?= =?us-ascii?q?ESYJPgjofgXR1AYhuX4FTAQEB?= X-IronPort-AV: E=Sophos;i="5.41,444,1498514400"; d="scan'208";a="288735640" Received: from mail-wm0-f53.google.com ([74.125.82.53]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 29 Aug 2017 15:31:28 +0200 Received: by mail-wm0-f53.google.com with SMTP id t201so2247075wmt.1 for ; Tue, 29 Aug 2017 06:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chawdhary-co-uk.20150623.gappssmtp.com; s=20150623; h=references:user-agent:from:to:cc:subject:message-id:in-reply-to :date:mime-version; bh=WRlEhh2wW7xDblKbV62hZc3EJleFnI/9MYEvsbrllG4=; b=gfa1t4RmZtrgsc6IT/rOGMGsc5vr4HDSmLj3yJs8+YHYmhPjDDnGTjhzk68AFMAhJ6 xMHZYKZVjfj17ZXkQUMdi9F7y+lK4YmCnay+7qQK1Z9vZoC1RfNtTGcDJr5/acTRYhzh eNq38MzLH25PN47/Pz+PSqwJyukEoUp5BpXlkaM6UJf6drFU83lM8W+YU5c+autz881A q2w43cpaJIihSQczrZzy5jR5D7rpZ9D4kfGZUmhuS+Mdtn3/h43il36vw3ELpgPq3xuP eWfbGrvTWsJFqvQ2UUdDQD1LoEDEGZITLEULnvUazE2Hs69Z2cn4dzzSGRIuY2Qpy82D kztA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :message-id:in-reply-to:date:mime-version; bh=WRlEhh2wW7xDblKbV62hZc3EJleFnI/9MYEvsbrllG4=; b=Wb0CxMXCC+NWyKJ6D1UGiqd+wWA5fDGCOc7WFYE+JxX4gzcnBKjuQBAJDH4les7wwQ AHAgF7TiJKlaBaOI5Ror3tmDEMrK5tdYzz/jehsrTHpdUSo1FhMiQkWSw/XaUvp++WOw kz1Lj6j3a4NhCeRFRBJ3o6MtYr9UXl6JnUNwIrRep8yVdB8Ph/pWOF59vjGyVbsquz+b GabH1DWY55uNRsTUvlkf53UvBP5dofKpxRtOgin5xKtYmTlvEsAKInN5a21XZJUmOsXg GNpYtgC2awwRCWLmW3Hmktk241FP0BjwUh44X36NJz93ran1TQkDzl93ksiCOCTIEWQ1 q6UQ== X-Gm-Message-State: AHYfb5j/fEYMwbojhMbZQtds7LfRdQDQ/8I3NIUH3De9OMkuw/7rUC8d QhbLsLrDThJ8m/Kgu4y3RA== X-Google-Smtp-Source: ADKCNb5NkeTnh7FeKPNXmKApRNZgT+exG0ZJjSibHCe485BuN4WKDppJBVGPyH7HYHDvagmYBFO0dg== X-Received: by 10.28.238.211 with SMTP id j80mr1210307wmi.182.1504013487571; Tue, 29 Aug 2017 06:31:27 -0700 (PDT) Received: from localhost (eduAAF0.kent.ac.uk. [129.12.170.240]) by smtp.gmail.com with ESMTPSA id 16sm1651910wmg.10.2017.08.29.06.31.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Aug 2017 06:31:25 -0700 (PDT) References: User-agent: mu4e 0.9.16; emacs 25.2.1 From: Aziem Chawdhary To: Kenneth Adam Miller Cc: caml users Message-ID: In-reply-to: Date: Tue, 29 Aug 2017 14:31:24 +0100 MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Caml-list] oasis and C wrapper Hi Kenneth, I don't know if you have solved this problem yet, but I have a small example of building a static C lib and statically linking with OCaml using Oasis and OCamlbuild. The repository is here: https://github.com/aziem/ctypes-static-lib-ocamlbuild and I think the most relevant example for you is under the oasis-lib branch. This example uses ocamlbuild to do most of the work rather than trying to get options set correctly in the _oasis file. So I use ocamlbuild tags and a small myocamlbuild plugin and get everything built correctly. This example uses information from various sources, including those you linked to in your first email, as well as information from the OCaml-Ctypes issue tracker. The repository is mainly for my own documentation purposes but may be of use to you. Hope this helps, Aziem Kenneth Adam Miller writes: > Ok I think I found the source of the error - this was in the _build/_log: > > ### Starting build. > Backtrace: > - Failed to build the target libdai_stubs.a > - Building libdai_stubs.a: > - Failed to build all of these: > - Building libdai_stubs.cmx: > - Failed to build all of these: > - Building libdai_stubs.ml: > - Failed to build all of > these: > - Building > libdai_stubs.mly > - Building > libdai_stubs.mll > - Building libdai_stubs.mlpack > - Building libdai_stubs.mllib > - Building libdai_stubs.clib > # Compilation unsuccessful. > > The problem is that libdai_stubs.a is already built, and ocamlbuild is > trying to build it again! Also, I followed the with-c oasis example to a T, > and theirs never tried to build .cmx/mllib/mlpack/mly/mli suffixed > auto-generated C source file targets. So why would it try and do that with > mine?? I found that changing the library name of mine in my _oasis causes > oasis/ocamlbuild to search for an appropriately named .ml file. But that > doesn't happen in the with-c example, and not only that, the with-c example > doesn't have a with-c.ml file anyway?! Also my issue has been replicated in > two different dockers, stale mated on a Mac, and then also within an ubuntu > vm. > > I can't make this opam package until I get oasis and ocamlbuild to work > together. > > On Sun, Aug 27, 2017 at 3:56 PM, Kenneth Adam Miller < > kennethadammiller@gmail.com> wrote: > >> Ok, so I got the with-c example to build by running -configure before I >> built with ocaml setup.ml -build, and that worked. But then there's a >> part in there where ocamlbuild is passed a libwith-c_stubs.a target and it >> knows what to do with it. I've tried to copy that example line by line in >> my _oasis and command line steps, and I have know what calls ocamlbuild >> should be making to get the .cma and .cmxa targets. But I can't get my >> _oasis to work. >> >> On Sun, Aug 27, 2017 at 1:19 AM, Kenneth Adam Miller < >> kennethadammiller@gmail.com> wrote: >> >>> Actually, I think it's that ocamlbuild should be told to link >>> libdai_stubs.a, and not try and build it. But also, I wanted to reference >>> an existing work that links with C libraries, and I found ocamlbuild's >>> example, with-c. I tried to build it, and I found that it isn't built by >>> the harness default. Also, if you just try and build within just that raw >>> directory in isolation, that it fails with a similar error I had been >>> getting earlier. I looked around and found these: >>> >>> https://stackoverflow.com/questions/19644451/how-to-make- >>> ocamlbuild-compile-and-link-a-c-file-into-an-ocaml-project >>> https://l-lang.blogspot.com/2012/08/incorporating-c-code-in- >>> ocaml-project.html >>> https://ocaml.org/learn/tutorials/ocamlbuild/Using_an_extern >>> al_library.html >>> >>> And I'm trying to follow, but they each give unique directions, each seem >>> to not work for me. >>> >>> On Sat, Aug 26, 2017 at 9:12 PM, Kenneth Adam Miller < >>> kennethadammiller@gmail.com> wrote: >>> >>>> Hello, >>>> >>>> >>>> I'm building a pair of companion oasis build spec and opam package setup >>>> for a C library. libdai I figured out how to get swig and oasis to build >>>> most things I need, but I'm having trouble getting oasis to not generate >>>> _stubs targets that aren't found. There is a static C/++ libdai.a file that >>>> is the product of the project I'm trying to wrap. I can't convince oasis to >>>> use that instead. Here's my _oasis target: >>>> >>>> >>>> Library "dai" >>>> Path: ./ >>>> Install: false >>>> Modules: Swig, Dai >>>> CompiledObject: best >>>> CSources: dai_wrap.cxx.c >>>> CCOpt: -g -xc++ "-I../../include" >>>> >>>> >>>> With a fresh clone of libdai, I get dai_wrap.cxx.c by doing the >>>> following in ./swig after building libdai: >>>> >>>> $(SWIG) -ocaml -c++ dai.i >>>> mv dai_wrap.cxx dai_wrap.cxx.c >>>> sed -i -e 's/caml_array_length/caml_array_len/g' dai_wrap.cxx.c >>>> >>>> I got my swig and dai ml files by doing the following: >>>> >>>> swig2.0 -ocaml -co dai.ml >>>> swig2.0 -ocaml -co swig.ml >>>> swig2.0 -ocaml -co swig.mli >>>> >>>> I build by doing the following: >>>> >>>> ocaml setup.ml -configure >>>> ocaml setup.ml -build >>>> >>>> >>>> I get the following error: >>>> >>>> >>>> Solver failed: >>>> Ocamlbuild knows of no rules that apply to a target named >>>> ./libdai_stubs.a. This can happen if you ask Ocamlbuild to build a target >>>> with the wrong extension (e.g. .opt instead of .native) or if the source >>>> files live in directories that have not been specified as include >>>> directories. >>>> Compilation unsuccessful after building 8 targets (8 cached) in 00:00:00. >>>> E: Failure("Command ''/usr/bin/ocamlbuild' ./libdai_stubs.a >>>> ./dlldai_stubs.so ./dai.cma ./dai.cmxa ./dai.a ./dai.cmxs -j 5 -tag debug' >>>> terminated with error code 6") >>>> >>>> I want to make sure that the actual target shared library that was >>>> produced by the libdai build file itself is linked against. But oasis is >>>> assuming I have a _stubs target. I read in the documentation here that: "The >>>> usual idiom is to append _stubs to the name." >>>> https://ocaml.org/learn/tutorials/setting_up_with_oasis.html >>>> #Interfacing-with-C-code >>>> >>>> And I think that that is the source of the error, but it isn't well >>>> explained. The ultimate things I originally wanted was to be able to use >>>> libdai with both the utop or the bytecode interpreter and with fully >>>> compiled targets. I was going to make libdai a library and then publicize >>>> it. >>>> >>>> If anybody needs to replicate my issue, I have a docker container with >>>> this already. >>>> >>> >>> >> --