caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kakadu <kakadu.hafanana@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Re: Link problems when startup from C++
Date: Sun, 24 Mar 2013 17:09:45 +0400	[thread overview]
Message-ID: <CAGmVoG1Yv6cOuyz++DbypDxPgOE+nC_2yYKW7L4SjDTswACR3Q@mail.gmail.com> (raw)
In-Reply-To: <CAGmVoG2t2NqFtFSO0TbFyengdk6SE2p=GeyNaTohJjBKV_+Gbw@mail.gmail.com>

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 <C++ and OCaml object files> -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 <kakadu.hafanana@gmail.com> 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

      reply	other threads:[~2013-03-24 13:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-24  8:00 [Caml-list] " Kakadu
2013-03-24 13:09 ` Kakadu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGmVoG1Yv6cOuyz++DbypDxPgOE+nC_2yYKW7L4SjDTswACR3Q@mail.gmail.com \
    --to=kakadu.hafanana@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).