我正在尝试使用混合C和Ocaml源编译程序,C中的应用程序主要调用一些OCaml代码.好吧,这里没问题,这似乎是一个常见的操作,完全记录,易于使用标准的Ocaml工具.
让我解释一下,这种编译分为4个步骤:Caml编译为Caml对象,然后将Caml编译为C对象,然后编译C文件,最后编译所有C对象并获取可执行文件.
理论上,Ocaml编译器将自动嵌入Caml运行时,GC及其所有内容,我们只需要指出我们是使用ocaml字节码(引用-lcamlrun)还是本机二进制(引用-lasmrun).
所以,它似乎很简单,让我们这样做.第1步,第2步和第3步按预期进行,很好!只有第四步是有问题的.看看:
cc -o /home/thomas/Documents/projects/ocaml/GogoGame/bin/GogoPlayer.exe \
-L/usr/lib/ocaml -lcamlrun \
/home/thomas/Documents/projects/ocaml/GogoGame/src/init_camlcode.o \
/home/thomas/Documents/projects/ocaml/GogoGame/src/init.o \
/home/thomas/Documents/projects/ocaml/GogoGame/src/interface.o \
/home/thomas/Documents/projects/ocaml/GogoGame/src/caml_func.oo
/home/thomas/Documents/projects/ocaml/GogoGame/src/interface.o: In function `main':
interface.c:(.text+0x0): multiple definition of `main'
/usr/lib/ocaml/libcamlrun.a(main.o):(.text+0x0): first defined here
/usr/lib/ocaml/libcamlrun.a(floats.o): In function `caml_exp_float':
(.text+0x488): undefined reference to `exp'
/usr/lib/ocaml/libcamlrun.a(floats.o): In function `caml_fmod_float':
(.text+0x4f9): undefined reference to `fmod'
/usr/lib/ocaml/libcamlrun.a(floats.o): In function `caml_log_float':
(…)
/usr/lib/ocaml/libcamlrun.a(unix.o): In function `caml_dlopen':
(.text+0x2ed): undefined reference to `dlopen'
/usr/lib/ocaml/libcamlrun.a(unix.o): In function `caml_dlclose':
(.text+0x300): undefined reference to `dlclose'
/usr/lib/ocaml/libcamlrun.a(unix.o): In …Run Code Online (Sandbox Code Playgroud)