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
[Doc] adds for -output-complete-obj
option
#1351
Conversation
AFAIR that's actually not the case, you have to link libasmrun and your libraries when you produce your executable.
You might want to link with a runtime variant. |
When doing a let files, c_lib =
if (not !Clflags.output_c_object) || main_dll || main_obj_runtime then
files @ (List.rev !Clflags.ccobjs) @ runtime_lib () @ libunwind,
(if !Clflags.nopervasives || main_obj_runtime
then "" else Config.native_c_libraries)
else
files, "" I tested it that work without linking the runtime. Perhaps a test should be added for the creation of shared libraries.
Differently than by using
|
Sorry I missed the shared aspect what is written as a comment there seems consistant with what is written about the worfklow here, I thought That said I don't really see why |
Ok, it just seemed difficult to grasp the differences, but keeping the simple variant seems indeed useful. |
What is the current status of this PR, is it proposed for merge? |
-output-complete-obj
option-output-complete-obj
option
@gasche I think it is. |
@dbuenzli, do you like the current state? (Do you "approve" the PR?) |
manual/manual/cmds/intf-c.etex
Outdated
C object file (".o" file, ".obj" under Windows) containing the | ||
bytecode for the OCaml part of the program, as well as a | ||
"caml_startup" function. The C object file produced by "ocamlc | ||
-output-complete-obj" also contains the runtime and autolink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the larger context defines the notion of autolink
libraries. But I guess that's the C linking instructions that are embedded in ocaml object's files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wording is already used for the -noautolink
option.
manual/manual/cmds/intf-c.etex
Outdated
This use of "-output-complete-obj" is very similar to a normal linking | ||
step, but instead of producing a main program that automatically runs | ||
the OCaml code, it produces a shared library that can run the OCaml | ||
code on demand. The three possible behaviors of "-output-complete-obj" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I don't understand something but isn't it the case that:
-output-obj
:.{o,a}
-> only the ocaml program,.so
-> ocaml program + runtime libraries + autolink (?)-output-complete-obj
:.{o,a,so}
-> ocaml program + runtime libraries + autolink
So I'm not sure I understand this "three possible behaviours" of -output-complete-obj
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With ocamlc
a .c
can be produced with the two options. And in fact a .a
can never be produced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I understand, the two options -output-obj
and -output-complete-obj
have the same behavior when producing a shared library or a c file. Would it not make sense to mention both of them in the previous paragraph?
manual/manual/cmds/intf-c.etex
Outdated
@@ -1597,9 +1603,27 @@ With "ocamlopt", you should do: | |||
% -output-obj" already contains the OCaml runtime library as | |||
% well as all the needed C libraries. | |||
|
|||
For the final linking phase, in addition to the object file produced | |||
by "-output-complete-obj", you will have only to provide all C | |||
libraries that are required by the OCaml runtimes used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provide the C libraries required by the OCaml runtime
manual/manual/cmds/intf-c.etex
Outdated
Unix library. With "ocamlc", you should do: | ||
\begin{alltt} | ||
ocamlc -output-complete-obj -o camlcode.o unix.cma {\it{other}} .cmo {\it{and}} .cma {\it{files}} | ||
cc -o myprog {\it{C objects and libraries}} \char92 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't find that particularly intelligible and rather ambiguous, maybe camlcode.o + -lc -lm
? In particular it seems to me that should not repeat the autolink libraries here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is indeed strange that the autolink libraries are added but you still need the library of the runtime. It is not always -lc -lm
it could be -lm -ldl
, no? I can't add $(ocamlopt -config | sed -n -e "s/^native_c_libraries:\(.*\)$/\1/p")
so perhaps {\it{C libraries required by the runtime, eg -lm -ldl}}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just suggesting examples of what you may need to add here. It's just that it should be made clear that you should not add the autolink libs otherwise you will be subject to double linking. I just find that not very clear in the current text.
(Aside. For this reason I personally find the behaviour of -output-complete-obj
dubious, you may have other C object files at that point that need the C libs that you autolinked via -output-complete-obj).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In your case you are not the target audience for -output-complete-obj
.)
manual/manual/cmds/intf-c.etex
Outdated
With "ocamlopt", you should do: | ||
\begin{alltt} | ||
ocamlopt -output-complete-obj -o camlcode.o unix.cmxa {\it{other}} .cmx {\it{and}} .cmxa {\it{files}} | ||
cc -o myprog {\it{C objects and libraries}} \char92 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above.
I don't understand why |
So what's the current status of this? It looks like you are both slightly confused about some of the aspects of |
I think that it would valuable to have correct and precise documentation and whoever added that command line switch should do it. |
Reading the original mantis ticket, it seems to me that the original intent was to not link |
@Octachron I agree. |
We should try to merge this PR even if not perfect. But it needs to be updated for #8872 (if that PR is merged before). |
@nojb Could you do the update? You already have the right to modify my repo. |
PR rebased. Formal review/approval would be appreciated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar corrections, cut long lines, and some rewording for the byte-code case. This PR is nearly ready for merge.
Thanks for the review @damiendoligez! I think all points have been addressed. |
Good. All we need now is a rebase and a |
Done. Good to go once CI is green. |
Co-authored-by: Thibaut Mattio <thibaut.mattio@gmail.com>
Try to add documentation for
-output-complete-obj
. However the comment in the latex of @damiendoligez about the doc of-output-obj
is still true:I'm wondering if the documentation shoudn't be written by saying that
-output-obj
is deprecated and just talk about-output-complete-obj
. Is there a need for the building of not shared libraries that doesn't contains the runtime and C stub?Closes #8882