Hi,<br><br>I think I have found the problem. It&#39;s in the structure of the Makefile generated by CMake. For each target, make is called on a sub Makefile and this is problematic for OCaml. I have reproduced the problem with an handwritten Makefile (see attachment).<br>
<br>Try make -j all2 and make -j all1. The first command will always work whereas the second, with recursive calls to make, will fail sometimes.<br><br>Recursive Makefiles with OCaml seem to be incompatible with parallel make. In OCaml, each object depends on others. If two targets depend on io.cmx and if make is launched in parallel on these two targets, the file io.cmx will be built twice. And if the first make command builds the object whereas the second tries to link the executable at the same time, the link command will fail because the object is being corrupted.<br>
<br>I think it&#39;s only a problem for OCaml. In C or C++, objects only depend on sources, and not on objects previously compiled.<br><br>Do you agree with this explanation ?<br><br>I see one solution : add a macro to create an only target with all OCaml libraries and executables, but it&#39;s not perfect.<br>
<br>Bye,<br><br>J. Bedouet<br><br><br><br><div class="gmail_quote">2010/1/22 Keyan <span dir="ltr">&lt;<a href="mailto:ml@pulsschlag.net">ml@pulsschlag.net</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hi,<br>
<br>
i didnt have much time lately to look deeply into the scripts. at first i thought that one has to add some add_dependencies, which was my first strategy, before i wrote useocaml.cmake. but then i saw, that i removed them, because i got the DEPENDS right. so my guess was wrong.<br>

<br>
what you write seems plausible. i got the messages with your script when i compiled with make -j 2 while my computer was busy. for some reason i didnt get them with my scripts yet, which could just be by chance.<br>
<br>
i do not know how to proceed from here on.<br>
<br>
anyone got an idea?<br>
<br>
cheers,<br>
<font color="#888888">keyan<br>
</font><div><div></div><div class="h5"><br>
<br>
<br>
On 22 Jan 2010, at 02:16, Judicaël Bedouet wrote:<br>
<br>
&gt; Hello,<br>
&gt;<br>
&gt; I try to compare Makefiles generated by your scripts and mine. I don&#39;t see any big differences, except the copy rules.<br>
&gt;<br>
&gt; While trying your scripts, I also reproduced a similar bug.<br>
&gt;<br>
&gt; Generating file_node.cmx<br>
&gt; Generating message_node.cmi<br>
&gt; Generating file_node.cmi<br>
&gt; File &quot;/Users/judi/src/ocaml/cmake/<br>
&gt; code-analysis/build/<a href="http://file_node.ml" target="_blank">file_node.ml</a>&quot;, line 1, characters 0-1:<br>
&gt; Error: Corrupted compiled interface<br>
&gt; file_node.cmi<br>
&gt; make[2]: *** [file_node.cmx] Error 2<br>
&gt;<br>
&gt; Try with<br>
&gt; while true; do make clean; make -j; done<br>
&gt; and you will reproduce it.<br>
&gt;<br>
&gt; I think dependencies in our scripts are good (or almost good). The reason may be elsewhere.<br>
&gt;<br>
&gt;<br>
&gt; I don&#39;t see a solution yet but I have found a promising lead. When two targets depends on the same object, make tries to build the object twice.<br>
&gt;<br>
&gt; If make builds the same object twice at the same time, the command &#39;cmake -E copy_if_different&#39; may be called at the same time and one of the cmake command fails because it can&#39;t open the file. I suppose it&#39;s the reason of<br>

&gt;<br>
&gt; &gt; Error copying file (if different) from &quot;[...]/code-analysis-build/Dependencies/message_node.ml.dep.cmake.tmp&quot;<br>
&gt; &gt; to &quot;[...]/code-analysis-build/Dependencies/message_node.ml.dep.cmake&quot;.<br>
&gt;<br>
&gt; In your code, the loc and messages executables depends both on io.cmo. Sometimes, it tries to link loc and build io.cmo (probably for messages) at the same time. I suppose it&#39;s the reason of<br>
&gt;<br>
&gt;<br>
&gt; &gt; Building OCaml object io.cmo<br>
&gt; &gt; Building OCaml object files.cmo<br>
&gt; &gt; [  0%] Linking OCaml executable loc<br>
&gt; &gt; File &quot;_none_&quot;, line 1, characters 0-1:<br>
&gt; &gt; Error: The file /Users/judi/src/ocaml/cmake/code-analysis/build/io.cmo is not a bytecode object file<br>
&gt;<br>
&gt;<br>
&gt; I add a third target which depends on io.cmo (create a common library and make loc and messages depend on this library). It appears that make tries to build the object io.cmo three times and build fails are almost systematic.<br>

&gt;<br>
&gt;<br>
&gt; If you keep only one target, there is never no problems.<br>
&gt;<br>
&gt;<br>
&gt; An idea ? Too late in the night for me :-(<br>
&gt;<br>
&gt;<br>
&gt; Bye,<br>
&gt;<br>
&gt; J. Bedouet<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; 2010/1/20 Keyan &lt;<a href="mailto:ml@pulsschlag.net">ml@pulsschlag.net</a>&gt;<br>
&gt; hi,<br>
&gt;<br>
&gt; i started to work on your scripts. very nice work!<br>
&gt;<br>
&gt; unfortunately, i couldnt find the problem, and i cant reproduce it with my scripts. there must be a difference somewhere.<br>
&gt;<br>
&gt; cheers,<br>
&gt; keyan<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On 19 Jan 2010, at 00:30, Judicaël Bedouet wrote:<br>
&gt;<br>
&gt; &gt; Hi,<br>
&gt; &gt;<br>
&gt; &gt; Effectively, I have reproduced your two bugs by using make -j. It&#39;s not systematic (once in ten).<br>
&gt; &gt;<br>
&gt; &gt; &gt;&gt; Error: The file /Users/zahedi/Downloads/code-analysis-build/io.cmo is not a bytecode object file<br>
&gt; &gt; When this error occurs, it also appears that the object is being built. And if I rerun make, linking is correct, without rebuilding io.cmo.<br>
&gt; &gt;<br>
&gt; &gt; Building OCaml object io.cmo<br>
&gt; &gt; Building OCaml object files.cmo<br>
&gt; &gt; [  0%] Linking OCaml executable loc<br>
&gt; &gt; File &quot;_none_&quot;, line 1, characters 0-1:<br>
&gt; &gt; Error: The file /Users/judi/src/ocaml/cmake/code-analysis/build/io.cmo is not a bytecode object file<br>
&gt; &gt;<br>
&gt; &gt; Dependencies in the generated Makefile seem to be correct :<br>
&gt; &gt; loc: file_node.cmo<br>
&gt; &gt; loc: files.cmo<br>
&gt; &gt; loc: io.cmo<br>
&gt; &gt; loc: file_statistics.cmo<br>
&gt; &gt; loc: message_node.cmo<br>
&gt; &gt; loc: loc.cmo<br>
&gt; &gt;<br>
&gt; &gt; Is OCaml parallel make safe ? I&#39;m not sure... I readd CMake address : maybe someone has an idea...<br>
&gt; &gt;<br>
&gt; &gt; To speed up compilation, I could look for ocamlc.opt and if not found ocamlc. Bytecode compilations should be faster.<br>
&gt; &gt;<br>
&gt; &gt; J. Bedouet<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; 2010/1/18 Keyan &lt;<a href="mailto:ml@pulsschlag.net">ml@pulsschlag.net</a>&gt;<br>
&gt; &gt; hi,<br>
&gt; &gt;<br>
&gt; &gt; i am just trying to reproduce the message i posted. i cant, but i got something else:<br>
&gt; &gt;<br>
&gt; &gt; Error: The file /Users/zahedi/Downloads/code-analysis-build/io.cmo is not a bytecode object file<br>
&gt; &gt;<br>
&gt; &gt; i use make -j 2 (at least 2), and my guess is that it has to do with parallel compilation. could that be the case?<br>
&gt; &gt;<br>
&gt; &gt; cheers,<br>
&gt; &gt; keyan<br>
&gt; &gt;<br>
&gt; &gt; On 18 Jan 2010, at 18:01, Judicaël Bedouet wrote:<br>
&gt; &gt;<br>
&gt; &gt; &gt; Hi,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;&gt; first of all, wow, good job! very nice scripts, much more sophisticated then mine :)<br>
&gt; &gt; &gt; Thanks :-)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;&gt; I only had one error when first trying: Error copying file (if different) from &quot;[...]/code-analysis-build/Dependencies<br>
&gt; &gt; &gt; &gt;&gt; /message_node.ml.dep.cmake.tmp&quot; to &quot;[...]/code-analysis-build/Dependencies/message_node.ml.dep.cmake&quot;.<br>
&gt; &gt; &gt; Maybe the Dependencies directory is not created. It is done at line 32 of OCamlDep, though. Let me know if you find something.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I have tested my scripts with OCaml 3.10 and I have found that ocamlfind is officially distributed with OCaml since 3.11. Maybe, I should put ocamlfind stuff in a FindOCamlFind script...<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; J. Bedouet<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; 2010/1/18 Keyan &lt;<a href="mailto:ml@pulsschlag.net">ml@pulsschlag.net</a>&gt;<br>
&gt; &gt; &gt; Hi,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; i am sorry that i could not reply any sooner.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; first of all, wow, good job! very nice scripts, much more sophisticated then mine :)<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; i only had one error when first trying:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Error copying file (if different) from &quot;[...]/code-analysis-build/Dependencies/message_node.ml.dep.cmake.tmp&quot; to &quot;[...]/code-analysis-build/Dependencies/message_node.ml.dep.cmake&quot;.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; i will try to solve that myself. this way i know if i understand your scripts.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; cheers,<br>
&gt; &gt; &gt; keyan<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; On 16 Jan 2010, at 14:51, Judicaël Bedouet wrote:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Hi,<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Here are my OCaml scripts, with your OCaml code (it helped me to find a bug about a source file included in two targets).<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; I have kept your idea about an only macro to compile and link, reused your macro ocaml_parse_arguments (I should use for my other macros :-) ) and added a macro find_ocaml_package to find ocaml packages with ocamlfind.<br>

&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; Tell me what you think,<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; J. Bedouet<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; 2010/1/15 Keyan &lt;<a href="mailto:ml@pulsschlag.net">ml@pulsschlag.net</a>&gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; hi,<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; Indeed, it is much more sophisticated, so it may be more bugged ;-)<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; i can help debugging :)<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; shell i send you my scripts to take a look?<br>
&gt; &gt; &gt; &gt; &gt; It&#39;s not necessary. I have downloaded the refactoring branch of yars. Thanks.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; oh, ok, then you should have the newest version (last yars revision is 513).<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; I comment my OCaml scripts and I send you, so that you could also have a look.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; great.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; I have took a look at your UseOCaml script. I can&#39;t see why you copy ML files into the current binary dir before compiling them. Is there a reason ?<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; no. i copied most of the stuff from the UseLATEX.cmake. it was done so there, and at the time i wrote the script, i thought its a good idea. don&#39;t ask me why :)<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; Keep in touch,<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; let me know when i can jump in and help. looking forward.<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; cheers,<br>
&gt; &gt; &gt; &gt; keyan<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; J. Bedouet<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; On Fri, Jan 15, 2010 at 8:26 AM, Keyan &lt;<a href="mailto:ml@pulsschlag.net">ml@pulsschlag.net</a>&gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; I totally agree.<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; Judicaël: how should we proceed? my first impression is that your usecaml.cmake is much more sophisticated then mine :) same for the findocaml.cmake scripts, as mine up to now does nothing more than to call a bunch of find_program commands.<br>

&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; shell i send you my scripts to take a look?<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; i have no problem with merging my stuff into your scripts, keeping you as main author, if there is anything useful for you.<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; cheers,<br>
&gt; &gt; &gt; &gt; &gt; keyan<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; On 15 Jan 2010, at 02:39, Philip Lowman wrote:<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; On Thu, Jan 14, 2010 at 5:11 AM, Keyan &lt;<a href="mailto:ml@pulsschlag.net">ml@pulsschlag.net</a>&gt; wrote:<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; hi,<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt;&gt; ups ... i thought i replied to the list. thanks for the link. i will adapt my find-script to the requirements and maintain the package.<br>
&gt; &gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; You should work with Judicaël to combine the best of both of your<br>
&gt; &gt; &gt; &gt; &gt; &gt; works together into one FindOCaml and UseOCaml script.  There is no<br>
&gt; &gt; &gt; &gt; &gt; &gt; sense having two of them out there.<br>
&gt; &gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt; &gt; --<br>
&gt; &gt; &gt; &gt; &gt; &gt; Philip Lowman<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
<br>
<br>
</div></div></blockquote></div><br>