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 227217EE80 for ; Sun, 24 Mar 2013 14:09:47 +0100 (CET) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of kakadu.hafanana@gmail.com) identity=pra; client-ip=209.85.128.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="kakadu.hafanana@gmail.com"; x-sender="kakadu.hafanana@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of kakadu.hafanana@gmail.com designates 209.85.128.51 as permitted sender) identity=mailfrom; client-ip=209.85.128.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="kakadu.hafanana@gmail.com"; x-sender="kakadu.hafanana@gmail.com"; 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-qe0-f51.google.com) identity=helo; client-ip=209.85.128.51; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="kakadu.hafanana@gmail.com"; x-sender="postmaster@mail-qe0-f51.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Aq4CADH4TlHRVYAzkGdsb2JhbABDxXOBaggWDgEBAQEJCRQUKIIkAQEFQAEbHgMMBgULDS4hAQERAQUBHAYTiAEBAw+jd4wygnuDUgoZJw1ZiHwBBQyMQYJSg0ADiHOFWoRUgWaBYItpgzkWKYQyNw X-IPAS-Result: Aq4CADH4TlHRVYAzkGdsb2JhbABDxXOBaggWDgEBAQEJCRQUKIIkAQEFQAEbHgMMBgULDS4hAQERAQUBHAYTiAEBAw+jd4wygnuDUgoZJw1ZiHwBBQyMQYJSg0ADiHOFWoRUgWaBYItpgzkWKYQyNw X-IronPort-AV: E=Sophos;i="4.84,900,1355094000"; d="scan'208";a="9029038" Received: from mail-qe0-f51.google.com ([209.85.128.51]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Mar 2013 14:09:46 +0100 Received: by mail-qe0-f51.google.com with SMTP id nd7so2958371qeb.24 for ; Sun, 24 Mar 2013 06:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=OJd6pAOvWSsbV3w8NGQqep0tzUci2n96dx0QxDrsDTw=; b=ZUof+PXCK6A8gGgwAjjvamCa+ZrT/Bn8K0uBjqAJLm0/1iSNHfF2xZpSPIGqcwzKHD EAOwneMpSN1YSy+WjpeLUARq1ILPQ5UrusGgxYy34peNuoCZirwUAmry6MgnaRZIeLtf PMYVYoI6ps0RDfwo7jBKEnZA5DwF8Gm6yzctEUKyAg/qxgNitWspY4f6YgvqydGnue/V 1yOqBWzqOJdFa0Wthd6KDvf0zOYjSRDRF8/1QGvRfvpgtR57GtQPgxGX38jCeHGHsykm 00kW3650+t4unK//IqxeEbouDzUC/J01/pLhBZtUdWnO28icCoLdQCdj/+bB6gCoVLPH FJEA== MIME-Version: 1.0 X-Received: by 10.49.83.162 with SMTP id r2mr2927353qey.7.1364130585153; Sun, 24 Mar 2013 06:09:45 -0700 (PDT) Received: by 10.49.12.7 with HTTP; Sun, 24 Mar 2013 06:09:45 -0700 (PDT) In-Reply-To: References: Date: Sun, 24 Mar 2013 17:09:45 +0400 Message-ID: From: Kakadu To: Caml List Content-Type: text/plain; charset=ISO-8859-1 Subject: [Caml-list] Re: Link problems when startup from C++ Issue is fixed now. 1. It is wrong to add linking information while generating .o file from OCaml .cmx files. Object files can't contain information about dependencies, it is external. So right command was ocamlfind opt -package compiler-libs.common,unix -linkpkg -output-obj -dstartup -I ../_build ../_build/qml_wrap.cmxa \ DataItem.cmx MainModel.cmx MiniModel.cmx program.cmx -linkall -o camlcode.o After that unix.a will be inside camlcode.o. 2. I needed to add linking commands to GCC call. Like this: g++ -L$QT5_ROOT/qtbase/lib -lQt5Core -lQt5Qml -lQt5Quick -lQt5Gui -L`ocamlc -where` \ ../_build/stubs.o -lm -ldl -lasmrun \ -lunix -o main Parameter '-lunix' adds 'libunix.so' file to 'main' executable. This shared object contains implementation of stubs declared in unix.a. N.B. Order of arguments should be correct. When I put -lunix just after '-L`ocamlc -where`' linking have finished with same errors like in first letter. -------------- Kakadu On Sun, Mar 24, 2013 at 12:00 PM, Kakadu wrote: > Hey > > My OCaml code uses Unix findlib package and I compile it like this > > ocamlfind opt -package compiler-libs.common,unix -linkpkg -output-obj > -dstartup -I ../_build ../_build/qml_wrap.cmxa \ > -ccopt -L`ocamlc -where` -ccopt -lunix \ > DataItem.cmx MainModel.cmx MiniModel.cmx program.cmx -linkall > -o camlcode.o -verbose > Effective set of compiler predicates: > pkg_compiler-libs,pkg_compiler-libs.common,pkg_unix,autolink,native > + ocamlopt.opt -output-obj -dstartup -I ../_build -ccopt > -L/home/kakadu/.opam/4.00.1/lib/ocaml -ccopt -lunix -linkall -o > camlcode.o -verbose -I > /home/kakadu/.opam/4.00.1/lib/ocaml/compiler-libs > /home/kakadu/.opam/4.00.1/lib/ocaml/compiler-libs/ocamlcommon.cmxa > /home/kakadu/.opam/4.00.1/lib/ocaml/unix.cmxa ../_build/qml_wrap.cmxa > DataItem.cmx MainModel.cmx MiniModel.cmx program.cmx > + as -o '/tmp/camlstartup3ada06.o' 'camlcode.o.startup.s' > + ld -r -o 'camlcode.o' '/tmp/camlstartup3ada06.o' 'program.o' > 'MiniModel.o' 'MainModel.o' 'DataItem.o' '../_build/qml_wrap.a' > '/home/kakadu/.opam/4.00.1/lib/ocaml/unix.a' > '/home/kakadu/.opam/4.00.1/lib/ocaml/compiler-libs/ocamlcommon.a' > '/home/kakadu/.opam/4.00.1/lib/ocaml/stdlib.a' > > It seems that Unix should be statically linked to 'camlcode.o'. After > that I want to build executable. > > g++ -L$QT5_ROOT/qtbase/lib -lQt5Core -lQt5Qml -lQt5Quick -lQt5Gui > -L"`ocamlc -where`" -lunix \ > ../_build/stubs.o DataItem_c.o moc_DataItem_c.o MainModel_c.o > moc_MainModel_c.o MiniModel_c.o moc_MiniModel_c.o camlcode.o main.o > -lm -ldl -lasmrun \ > -o main > > And I get many error like this: > > camlcode.o: In function `camlProgram__files_in_dir_1009': > (.text+0x399a): undefined reference to `unix_opendir' > /home/kakadu/.opam/4.00.1/build/ocaml/otherlibs/unix/unix.ml:644: > undefined reference to `unix_close' > camlcode.o: In function `camlUnix__fun_2465': > /home/kakadu/.opam/4.00.1/build/ocaml/otherlibs/unix/unix.ml:644: > undefined reference to `unix_close' > camlcode.o: In function `camlUnix__fun_2157': > /home/kakadu/.opam/4.00.1/build/ocaml/otherlibs/unix/unix.ml:644: > undefined reference to `unix_setsid' > camlcode.o: In function `camlUnix__fun_2159': > /home/kakadu/.opam/4.00.1/build/ocaml/otherlibs/unix/unix.ml:644: > undefined reference to `unix_tcflow' > camlcode.o: In function `camlUnix__fun_2161': > /home/kakadu/.opam/4.00.1/build/ocaml/otherlibs/unix/unix.ml:644: > undefined reference to `unix_tcflush' > etc. > > Any ideas what I have done wrong? How to link to unix correctly? > > Kind regards, > Kakadu