* [Caml-list] Link problems when startup from C++
@ 2013-03-24 8:00 Kakadu
2013-03-24 13:09 ` [Caml-list] " Kakadu
0 siblings, 1 reply; 2+ messages in thread
From: Kakadu @ 2013-03-24 8:00 UTC (permalink / raw)
To: Caml List
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Caml-list] Re: Link problems when startup from C++
2013-03-24 8:00 [Caml-list] Link problems when startup from C++ Kakadu
@ 2013-03-24 13:09 ` Kakadu
0 siblings, 0 replies; 2+ messages in thread
From: Kakadu @ 2013-03-24 13:09 UTC (permalink / raw)
To: Caml List
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-03-24 13:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-24 8:00 [Caml-list] Link problems when startup from C++ Kakadu
2013-03-24 13:09 ` [Caml-list] " Kakadu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox