From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 39DEEBBAF for ; Tue, 15 Dec 2009 21:47:47 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsoBABuEJ0vRVaA6kmdsb2JhbACQK4QFhlc/AQEBAQkLCgcRrmExhT4hiEIBAgMFhCYEiyI X-IronPort-AV: E=Sophos;i="4.47,402,1257116400"; d="scan'208";a="39941073" Received: from mail-pw0-f58.google.com ([209.85.160.58]) by mail3-smtp-sop.national.inria.fr with ESMTP; 15 Dec 2009 21:47:46 +0100 Received: by pwi2 with SMTP id 2so180346pwi.17 for ; Tue, 15 Dec 2009 12:47:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=1uKP+Xe+E9jJbTYwnq1wu+GRHRAFUluwGvhl9NPep90=; b=EB+Hehl5YewuhVif8Drlsq+RAhTL/s7q3CV3X77VmAP+ztHsQf1II7qZjnHFom5Wgt Wxe79GLX1wVTbG1jZLtgSfw7aXnl6KdP19Wz1D9RVSBGbwYr5mdNw66ZF78qcj+3amSX 7Tbfs9nEQBkECGqFIvvGhZb9AjpBGX3aSZgxM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=XZ1qSWgZqZljCtn39J1ZvuPxW4+GbC5PObKMs3OxpNgX+5qLNqZZ+C5hQYc9QSccFi ohsmaqSNUBi/avLKyXhcKyitKQv5DThyR5Z8QedeXXU/4rJurKlflhd8XHuPa8FjV+Jb qavyXYKKEP3mSt4LjJU6ywpHU4fJQMOj2keYs= MIME-Version: 1.0 Sender: aaron678@gmail.com Received: by 10.143.153.41 with SMTP id f41mr5584wfo.331.1260910064885; Tue, 15 Dec 2009 12:47:44 -0800 (PST) In-Reply-To: <20091215135959.GM17061@janestreet.com> References: <20091215135959.GM17061@janestreet.com> Date: Tue, 15 Dec 2009 15:47:44 -0500 X-Google-Sender-Auth: 4198f507070a2238 Message-ID: Subject: Re: [Caml-list] linking errors involving cpp files From: Aaron Bohannon To: Mark Shinwell Cc: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; cpp:01 extern:01 extern:01 mlvalues:01 shinwell:01 ocaml:01 ocaml:01 cpp:01 compiler:01 mangling:01 mlvalues:01 2009:98 2009:98 pertaining:98 wrote:01 Yes, it seems you're right. I just need the "extern" annotation around the includes. extern "C" { #include #include #include } Thanks to everyone for the helpful comments. - Aaron On Tue, Dec 15, 2009 at 8:59 AM, Mark Shinwell w= rote: > On Tue, Dec 15, 2009 at 08:50:33AM -0500, Aaron Bohannon wrote: >> On Tue, Dec 15, 2009 at 1:59 AM, Robert Roessler wro= te: >> > Aaron Bohannon wrote: >> >> >> >> How do I link C++ code with OCaml? >> >> > You might try (when mixing C++ and OCaml) wrapping the whole thing in = an >> > 'extern "C" {...}' block (*including* the #includes and the entire mai= n >> > function). >> >> Thanks for the tip. =A0This does resolve the missing caml symbols (even >> when naming the file with a cpp extension). =A0However, my real program >> actually uses some C++ features. =A0I think I could convert it to a real >> C program, but I assumed there would be some other way. > > I suspect it will work if only the #include directives pertaining to Caml > header files are marked as 'extern "C"'. =A0You just need to tell the com= piler to > use the C linkage convention rather than the C++ name mangling convention= for > the external Caml functions that your program (implicitly or explicitly) = calls. > This is done at the function prototype site, not the call site. =A0Everyt= hing > else in the program should be unaffected. > > Xavier, could the headers have the guards added? =A0(I only spot-checked = one, > mlvalues.h, and that didn't appear to have it). > > Mark >