New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duplicate symbol errors when running ocamlopt #7266
Comments
Comment author: @nojb You are running into problems because when you compile testo.c it generates testo.o but testo.o is also generated when compiling testo.ml with ocamlopt. I guess ocamlopt overwrites the first testo.o with the one generated by testo.ml and therefore you end up trying to link twice the same object file. You can fix it by using a different .o file for the C code, like: cc -I You can also use the -output-obj argument of ocamlopt to achieve the same thing in a different way: ocamlopt -output-obj -o test_caml.o -c testo.ml but note that in this case you need to use caml_startup instead of caml_main. See http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html for more details. |
Comment author: arshad01 Thanks for looking into this issue. I did a quick check and indeed the program compiles and links successfully when I follow your instructions. I could also achieve the same result by renaming the .ml file. As this was a usage error on my part, this issue can be closed. (though adding a note to warn about this situation under the "Warning:" section of 19.7.5 could be considered) |
Comment author: @gasche Thanks for the careful bug report. I would like to improve documentation if possible, but your indications are not clear enough for me to know what to add. In particular, I don't know what you mean by 19.7.5, do you have a reference? (I suppose you mean a section of the Reference manual, but section numbers are not stable across OCaml versions so...) If you have a proposal for a text to add, it would also be warmly welcome. |
Comment author: arshad01 I was referring to section 19.7.5 of this document (the user's manual): http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html and section 19.7 is: http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#sec432 I will try to come up with a sample text of the change. Thanks |
Comment author: arshad01 Here is a suggested text. This is to be added just after the section 19.7.4 under a "Warning" subsection of the user manual (http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html). Please feel free to make changes to the text. When using caml_main in C to initialize OCaml runtime, care is needed when naming files so as to avoid duplicate symbol errors during ocamlopt linking phase. Specifically, the name of object file generated from the C file without extension must be different than that of OCaml file without extension. Hence, if the name of object file is AAA.o, the OCaml file must not be named AAA.ml and vice versa. Name either of the file differently; i.e. either BBB.o or BBB.ml, for example.The HTML text is follows: Warning:
|
Original bug ID: 7266
Reporter: arshad01
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2017-09-24T15:32:57Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: Mac OSX
OS: OSX El Capitan
OS Version: 10.11.5
Version: 4.03.0
Category: back end (clambda to assembly)
Monitored by: arshad01 @gasche
Bug description
Hello
This may not be a bug but an error of usage.
I have simple example where I am using "ocaml_main" in a C program to run Ocaml runtime. But the linking phase is generating duplicate symbol errors. Please see the attached files for details.
Any help is greatly appreciated.
Arshad
Steps to reproduce
Unzip the archive and then run the build_testo.sh script.
Additional information
files in zip:
File attachments
The text was updated successfully, but these errors were encountered: