已经在ocaml asmrun库中定义了main函数
main function already defined in ocaml asmrun library
我正试图从C程序中调用一些ocaml代码。我一直在关注这里的一些文档。c程序名为hello.c
,它正试图使用callme.ml
中定义的Ocaml函数。
与链接中一样,我分两步来完成:首先将ml文件编译为对象文件:
ocamlopt -output-obj -o callme2.o callme.ml
然后尝试用以下代码将其链接到我的"主"二进制文件:
gcc -Wall -I`ocamlopt -where` -L`ocamlopt -where` -lasmrun -lm -ldl -o hello hello.c callme2.o -lasmrun
但我遇到了以下问题:main
已经在libasmrun.a中定义,因此它与我自己的hello.c
:中的main
冲突
/tmp/ccANhYNH.o: In function `main':
hello.c:(.text+0x58): multiple definition of `main'
/home/orm/.opam/4.02.0/lib/ocaml/libasmrun.a(main.o):main.c:(.text+0x0): first defined here
我该如何解决这个问题?(正如库路径所示,我使用的是ocaml 4.02版本)
更新:这个问题更多地与正确使用C链接器标志有关,而不是与ocaml有关。按以下顺序使用标志可修复问题:
gcc -Wall -I`ocamlopt -where` -L`ocamlopt -where` -o hello hello.c -lasmrun callme2.o -lm -ldl -lasmrun
这很有趣,因为我认为在同一个程序中定义两次相同的函数名是违法的。也许这是该文件中的一个例外。
您的命令行有点奇怪,因为-lasmrun
出现了两次。
以下是对我有效的东西:
$ W=`ocamlopt -where`
$ gcc -I $W -L $W -o hello hello.c callme.o -lasmrun -lm -ldl
您可以在我的伪博客中看到一个工作示例:进一步的OCaml GC Dishamony。
(正如我所学到的,请确保遵守GC和谐的规则:-)
相关文章:
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- File.cpp.o:OpenPose 标志 CMakeFiles/.. 的多重定义/main.cpp.o:首先在这里定
- C++:main() 未捕获的异常的自定义格式
- C++/生成文件错误:未定义对"main"的引用
- 在命名空间中声明变量,在 main 中定义它,使其对所有其他文件可见
- 可视化 如何修复 c++ 中已经定义的 -main?
- 在 Linux 上编译 - 在函数 '_start' 中:(.text+0x20):对 'main' 的未定义引用
- C++错误:在类中取消对main的定义引用
- crt1.o:在函数"_start"中:(.text+0x20):对"main"的未定义引用
- Main.Obj中已经定义的主要
- main.cpp:(.text+0x8ea):在C++中未定义的引用
- 实用程序函数不会在 .h 文件中初始化并在 main 中定义.cpp
- C :使用Main中定义的对象方法的函数
- 已在main.obj中定义了双精度
- C++ 编译错误:- 使用Makefile对"main"进行多重定义
- C++编译错误:多个定义"main",但项目中只有一个 main 函数
- 你能定义 main() 来接受不仅仅是 argc/argv 参数吗?
- 谷歌基准自定义main
- 实现自定义Main函数
- 在类中定义main函数