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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id ADFD8BBAF for ; Tue, 15 Dec 2009 06:09:34 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiIBAImoJkvRVdi/kGdsb2JhbACQKIQFhlE/AQEBAQkJDAcTA64UMYUPIYhCAQIDBYQmBIsg X-IronPort-AV: E=Sophos;i="4.47,398,1257116400"; d="scan'208";a="42013238" Received: from mail-px0-f191.google.com ([209.85.216.191]) by mail1-smtp-roc.national.inria.fr with ESMTP; 15 Dec 2009 06:09:33 +0100 Received: by pxi29 with SMTP id 29so2672511pxi.1 for ; Mon, 14 Dec 2009 21:09:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=8Jl5tEbihIUgfCW1URKqjsy25dIp8HrWG2kO+TRvdok=; b=xl8nzD2ZOw+49SXooZhemw7PcEzAvsOLVQ/Z1+6As5rwBqzeT2zekz5kipGTQYg3de hVMW5xiNmdN7A3sIcYVuoaswZmepsqoyFjS9u6TULpTQ/yzpt39FqKraHt6Dr8x1ThgO uo15FNpf0HPYt2mSUQT1SJvLXijPpJNmoliC0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=vqbPOajTVvrX2zDy5ryhT+dxt5CosP+LuRh0p2R8eYy4jD7IAkrwcn7bN1UOOsiqVG QaQkH+u9Ov6G1Gj/v0rKfMPDiz2tk+Rm+thotl011TrdfFheGazb7vVJxc2bH+w8VGj9 0DO8kPj1ezGskxkojL+R0nasmh5xvb581NnWs= MIME-Version: 1.0 Sender: aaron678@gmail.com Received: by 10.143.27.12 with SMTP id e12mr3837707wfj.221.1260853772845; Mon, 14 Dec 2009 21:09:32 -0800 (PST) Date: Tue, 15 Dec 2009 00:09:32 -0500 X-Google-Sender-Auth: ee92bbd039453702 Message-ID: Subject: linking errors involving cpp files From: Aaron Bohannon To: OCaml List Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; cpp:01 ocaml:01 ocaml:01 cpp:01 mlvalues:01 argc:01 argv:01 argv:01 argc:01 gcc:01 lib:01 ocamlopt:01 cmx:01 gcc:01 lib:01 Hi, How do I link C++ code with OCaml? Let's say I have a main program in C/C++ and a function I want to call in OCaml: ---- main.c / main.cpp --- #include #include #include int main (int argc, char ** argv) { char * caml_argv[argc + 1]; int i; for (i = 0; i < argc + 1; i++) caml_argv[i] = argv[i]; caml_argv[argc] = NULL; caml_main (caml_argv); return 0; } -------- ---- test.ml ---- let f x = x + 1 let () = Callback.register "test" f -------- If I name the main program "main.c", I can compile the code like this with no trouble whatsoever: gcc -I /opt/local/lib/ocaml -c main.c ocamlopt -o main test.cmx main.o If I name the main program "main.cpp", and run the same commands--- gcc -I /opt/local/lib/ocaml -c main.cpp ocamlopt -o main test.cmx main.o ---then I get this: Undefined symbols: "_caml_atom_table", referenced from: _intern_alloc in libasmrun.a(intern.o) _intern_rec in libasmrun.a(intern.o) _caml_alloc in libasmrun.a(alloc.o) _caml_alloc_dummy_float in libasmrun.a(alloc.o) _caml_alloc_dummy in libasmrun.a(alloc.o) _caml_alloc_array in libasmrun.a(alloc.o) "___gxx_personality_v0", referenced from: _main in main.o CIE in main.o "_caml_code_area_start", referenced from: _extern_rec in libasmrun.a(extern.o) _extern_rec in libasmrun.a(extern.o) _segv_handler in libasmrun.a(signals_asm.o) _caml_code_checksum in libasmrun.a(intern.o) _intern_rec in libasmrun.a(intern.o) "_caml_code_area_end", referenced from: _extern_rec in libasmrun.a(extern.o) _segv_handler in libasmrun.a(signals_asm.o) _caml_code_checksum in libasmrun.a(intern.o) "caml_main(char**)", referenced from: _main in main.o ld: symbol(s) not found collect2: ld returned 1 exit status File "caml_startup", line 1, characters 0-1: Error: Error during linking Now I know gcc does something slightly different with cpp files, and I can eliminate the complaint about the __gxx symbol if I add "-cclib -lstdc++" (which I fully expected to need working with C++ programs). But why are the caml symbols missing!?!? (It took me over 2 hours to figure out it was the "cpp" extension that was the root of these missing caml symbols in my real program because that was the *last* thing I expected.) I'm using OCaml 3.11.1 on OS X 10.6.2. - Aaron