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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 3304E7ED11 for ; Mon, 3 Oct 2016 17:32:37 +0200 (CEST) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=vitorm2p@gmail.com; spf=Pass smtp.mailfrom=vitorm2p@gmail.com; spf=None smtp.helo=postmaster@mail-lf0-f41.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of vitorm2p@gmail.com) identity=pra; client-ip=209.85.215.41; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="vitorm2p@gmail.com"; x-sender="vitorm2p@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of vitorm2p@gmail.com designates 209.85.215.41 as permitted sender) identity=mailfrom; client-ip=209.85.215.41; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="vitorm2p@gmail.com"; x-sender="vitorm2p@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-lf0-f41.google.com) identity=helo; client-ip=209.85.215.41; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="vitorm2p@gmail.com"; x-sender="postmaster@mail-lf0-f41.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3AI2JfkxKzDLgy7eTyANmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgUKf3xwZ3uMQTl6Ol3ixeRBMOAuqgC0bed4/+ocFdDyK7JiGoFfp1IWk1Nou?= =?us-ascii?q?QttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXsq3G/pQQfBg/4fVIs?= =?us-ascii?q?YL+kQMiI0o/niKibwN76W01wnj2zYLd/fl2djD76kY0ou7ZkMbs70RDTo3FFKK?= =?us-ascii?q?x8zGJsIk+PzV6nvp/jtM0rzyMFsPsk84tEUL7mV6U+V71RSjo8YE4v48i+ixjI?= =?us-ascii?q?UQyVrkMRSGgXiBMAVxbE8BbgW83pmiT/v+t5niKdOJulHvgPRT2+4vIzG1fTgy?= =?us-ascii?q?AdOmth/Q=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0A2AQDZefJXhinXVdFdHQEXAQYBCgEBF?= =?us-ascii?q?gEBBQEBBQGCSTYBAQEBAYFxoxEGgWcEh3KGToUSggaDOIRNOBQBAQEBAQEBAQE?= =?us-ascii?q?BARIBAQEICwsJGS+CMhiCMBEdARseAxIQBzACJREBBQEOSYgQAQMXBJ4pggiBM?= =?us-ascii?q?j4yiz2Ba4JfBYNiChknDVODDwEBARsCBhCFXoJHh2iCAAstK4IvBZQghViPcYl?= =?us-ascii?q?ahhiMW4JPMYERHoNngVxxh1UBAQE?= X-IPAS-Result: =?us-ascii?q?A0A2AQDZefJXhinXVdFdHQEXAQYBCgEBFgEBBQEBBQGCSTY?= =?us-ascii?q?BAQEBAYFxoxEGgWcEh3KGToUSggaDOIRNOBQBAQEBAQEBAQEBARIBAQEICwsJG?= =?us-ascii?q?S+CMhiCMBEdARseAxIQBzACJREBBQEOSYgQAQMXBJ4pggiBMj4yiz2Ba4JfBYN?= =?us-ascii?q?iChknDVODDwEBARsCBhCFXoJHh2iCAAstK4IvBZQghViPcYlahhiMW4JPMYERH?= =?us-ascii?q?oNngVxxh1UBAQE?= X-IronPort-AV: E=Sophos;i="5.31,438,1473112800"; d="scan'208,217";a="195471855" Received: from mail-lf0-f41.google.com ([209.85.215.41]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 03 Oct 2016 17:32:34 +0200 Received: by mail-lf0-f41.google.com with SMTP id l131so160037952lfl.2 for ; Mon, 03 Oct 2016 08:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:subject:message-id:date:to:mime-version; bh=ekkI0MrsTOAkATLlar7PXvJZaS9u5PzauEDyiaxW82c=; b=l55jPV8d/4/gR9s4tj9Uqmwj3nQkDUaoKr6SF3qWdwumKxxQKuXUbayXiqHnj++mnj eAwKz5eyXf922fwYxAePG6nDiVhRl5vx9yeoOaXZuZa9gtkm8YgDkwHkZfikvyl3nl2F j2ViI9VdcgjFTJ+d5jTzz9OT1ZVQzebiSegcaglrtmaei2yVngwPQrn85faIJt3OYhws QCVeSL33i8it/CjKSCHF9Chjm7UCuuwY5WVxbTyDJhclGJOpnOg1WDKb1IlBPTPbCe5c jNbtetdCablxRq6ph8trteFBQR0lpOnFmA9Aat9i9BC/DiLXCmEX1esfrwdUwHx7bWuk 2Giw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:message-id:date:to:mime-version; bh=ekkI0MrsTOAkATLlar7PXvJZaS9u5PzauEDyiaxW82c=; b=U8uYjjWz47dI6EULGTQ18L6RkkgcJM9YbHrtXsnQnvCcqG9KoDIWbOFIO/+pCEiTXW 1aORCNMXD/eeVskWzNFKsUTRjwiTEcnCtP75Y/eYY8wali88wqMduvlRbzzwyaYPOtdL t/a4iHI7ZC6Afht9fBz5Cp5PIg2hMpVtsu2HLyPdcORLYrs1YCBt5U3jIDFc7BB9C8IH OU5HvwF/oMoWXTa9VoRl/rRvuLv/RxUegtT2bApPBFHZQqSiD98NDc2tN0IM0rCXICQo hyV38zlJ7LELtR6AbcMUt3zuQLY78noNOelsaS1Ww3lL/FUHPwVKk58xlhz4SyPc+iZZ n5Cg== X-Gm-Message-State: AA6/9Rlm9B6bl5AUBaGFQLpEmYxOp3sg1puHAo/JhzG7S+Kfea8IpOMT9CTf1P4s2CmBQw== X-Received: by 10.194.235.34 with SMTP id uj2mr3662017wjc.144.1475508753559; Mon, 03 Oct 2016 08:32:33 -0700 (PDT) Received: from vpereira-pc.dcc.fc.up.pt (out-traffic.dcc.fc.up.pt. [193.136.39.10]) by smtp.gmail.com with ESMTPSA id lz5sm34809597wjb.24.2016.10.03.08.32.32 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Oct 2016 08:32:32 -0700 (PDT) From: Victor Pereira Content-Type: multipart/alternative; boundary="Apple-Mail=_A52D8997-6A52-4027-9D21-6B79DF29BF2D" Message-Id: Date: Mon, 3 Oct 2016 16:32:31 +0100 To: caml-list@inria.fr Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) X-Mailer: Apple Mail (2.3124) Subject: [Caml-list] Interop C-OCaml --Apple-Mail=_A52D8997-6A52-4027-9D21-6B79DF29BF2D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello all! I have some function written in OCaml that I need to call in a C program. The OCaml function takes a string, performs some computation and also=20 outputs a string. Note that these types are not mandatory, just for testing= purposes.=20 Therefore, I defined a C function like: char * foo (char * inp) { =20=20 CAMLlocal1 (caml_inp) ; caml_inp =3D caml_copy_string (inp); =20=20 value * func =3D caml_named_value (=E2=80=9Cfoo") ; =20=20 if (func =3D=3D NULL) puts (=E2=80=9CUnable to load OCaml function!") ; return strdup(String_val(caml_callback(*func, oinp))); } I am able to correctly compile the file with: ocamlc -c foo.c (according to the manual) Next, I define the main.c file as: extern char * foo(char * inp); int main (int argc, char ** argv) { /* Initialize OCaml code */ caml_startup(argv); /* Do some computation */ char * inp =3D =E2=80=9Csome string"; printf ("%s\n", foo(inp)); =20=20 return 0; } However, I=E2=80=99m not able to compile the main.c file! The error output is the following:=20 Undefined symbols for architecture x86_64: "_caml_startup", referenced from: _main in main-05d208.o =E2=80=9C_foo", referenced from: _main in main-05d208.o I followed the instructions in the manual to interop C and OCaml when the main program is in the C side. Nevertheless, If I run the example in the manual, it works very well! Any idea on what am I doing wrong? Best, Vitor --Apple-Mail=_A52D8997-6A52-4027-9D21-6B79DF29BF2D Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hello all!

I have some function written i= n OCaml that I need to call in a C program.

The OCaml function takes a string, performs som= e computation and also 
outputs a string. Note th= at these types are not mandatory, just for testing purposes. 

Therefore, I defined a C = function like:

ch= ar * foo (char * inp) {
  
  CAMLlocal1 (caml_inp) ;
&nb= sp; caml_inp =3D caml_copy_string (inp);
  <= /div>
  value * func =3D caml_named_value (=E2=80=9Cfoo= ") ;
  
  if (func= =3D=3D NULL)
    puts (=E2=80=9CUnable to l= oad OCaml function!") ;

  return strdup(String_val(caml_callback(*func, oinp)));
<= div class=3D"">}

I am able to correctly compile the file with:
ocamlc -c foo.c (according to the manual= )

Next, I define = the main.c file as:

extern char * foo(char * inp);

int main (int argc, char ** argv)
{

&n= bsp; /* Initialize OCaml code */
  caml_startup(a= rgv);

  /* D= o some computation */
  char * inp =3D =E2=80=9Cs= ome string";

&nbs= p; printf ("%s\n", foo(inp));
  
  return 0;
}

However, I=E2=80=99m not able to com= pile the main.c file!
The error output is the followin= g: 

Undefined symbols for architecture x86_64:
  "_caml_startup", referenced from:
      _main in main-05d208.o
  =E2=80=9C_foo", referenced from:
      _main in main-05d208.o

I followed the instru= ctions in the manual to interop C and OCaml when
the main program is in the C side.
=
Nevertheless, If I run the exampl= e in the manual, it works very well!

Any idea on what am I doing wrong?

B= est,
Vitor


= --Apple-Mail=_A52D8997-6A52-4027-9D21-6B79DF29BF2D--