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 7F794BBAF for ; Tue, 15 Dec 2009 15:00:04 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnUBADAlJ0smachlmWdsb2JhbACbPwEBAQEBCAsKBxO8F4QrBI0m X-IronPort-AV: E=Sophos;i="4.47,400,1257116400"; d="scan'208";a="39915418" Received: from mx1.janestcapital.com ([38.105.200.101]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Dec 2009 15:00:03 +0100 Received: from nyc-qsv-mail1.delacy.com ([172.25.22.57]) by mx1.janestcapital.com with esmtp (Exim 4.69) (envelope-from ) id 1NKXwX-00084W-RT for caml-list@inria.fr; Tue, 15 Dec 2009 09:00:01 -0500 Received: from nyc-qsv-004.delacy.com ([172.25.22.194] helo=qsmtp.delacy.com) by nyc-qsv-mail1.delacy.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NKXwX-0007uS-Qe; Tue, 15 Dec 2009 09:00:01 -0500 Received: from lon-qws-r01.delacy.com ([172.30.3.51] helo=lon-qws-r01) by qsmtp.delacy.com with smtp (Exim 4.63) (envelope-from ) id 1NKXwW-0005zu-KC; Tue, 15 Dec 2009 09:00:01 -0500 Received: by lon-qws-r01 (sSMTP sendmail emulation); Tue, 15 Dec 2009 13:59:59 +0000 From: "Mark Shinwell" Date: Tue, 15 Dec 2009 13:59:59 +0000 To: Aaron Bohannon Cc: caml-list@inria.fr Subject: Re: [Caml-list] linking errors involving cpp files Message-ID: <20091215135959.GM17061@janestreet.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Spam: no; 0.00; shinwell:01 cpp:01 ocaml:01 ocaml:01 cpp:01 compiler:01 mangling:01 mlvalues:01 2009:98 2009:98 pertaining:98 wrote:01 wrote:01 naming:01 caml-list:01 On Tue, Dec 15, 2009 at 08:50:33AM -0500, Aaron Bohannon wrote: > On Tue, Dec 15, 2009 at 1:59 AM, Robert Roessler wrote: > > 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 main > > function). > > Thanks for the tip. This does resolve the missing caml symbols (even > when naming the file with a cpp extension). However, my real program > actually uses some C++ features. I 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"'. You just need to tell the compiler 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. Everything else in the program should be unaffected. Xavier, could the headers have the guards added? (I only spot-checked one, mlvalues.h, and that didn't appear to have it). Mark