Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006475OCamlOCaml generalpublic2014-06-30 11:302015-04-02 18:00
Assigned Towhitequark 
PrioritynormalSeverityfeatureReproducibilityhave not tried
PlatformOSOS Version
Product Version 
Target Version4.03.0+devFixed in Version 
Summary0006475: -o is ignored for C files
DescriptionThe -o option is ignored when compiling C files, which makes it slightly awkward to write object files to a directory other than the current directory.

For example, the following command

   ocamlc -c -o build/code.cmo src/

creates 'build/code.cmo' as expected, but the corresponding command for a C file

   ocamlc -c -o build/code.o src/code.c

creates 'code.o' in the current directory.
Attached Filespatch file icon ocamlc-c-o.patch [^] (4,616 bytes) 2014-12-21 13:02 [Show Content]

- Relationships

-  Notes
whitequark (developer)
2014-10-23 22:14

I should add that ocamlbuild should be fixed as well when this issue is resolved. It currently uses mv to move the .o from the current directory.
yallop (developer)
2014-10-24 15:27

There's a patch by @vbgl here: [^]
gasche (developer)
2014-12-21 11:50

whitequark, could you write a test case in the ocamlbuild testsuite to make sure your ocamlbuild patch works as expected? There already is some very light output-obj testing in
whitequark (developer)
2014-12-21 13:02

I have attached a new patch that contains:

  * @vbgl's fix
  * changes to ocamlbuild
  * ocamlbuild test
  * changes to Changes
gasche (developer)
2014-12-21 13:20
edited on: 2014-12-21 13:21

I merged the (very nice!) patch, but in trunk only rather than in the stable branch. My reasoning is that other build systems may have workarounds for this issue (we had to fix ocamlbuild) which may break now that it is fixed.

(We don't know yet whether there will be another minor release, but Damien seems to be thinking about it.)

Thanks to all of you for the report and bugfixes.

whitequark (developer)
2014-12-21 13:22

I believe this can be merged in stable, because the patch does not change the behavior *without -o*, and other buildsystems are unlikely to pass an option that does nothing. So the workarounds will still work.
whitequark (developer)
2014-12-21 19:05

(In other words we did not *have* to fix ocamlbuild, I just thought it would be much cleaner.)
gasche (developer)
2014-12-21 19:11

Okay, will merge in 4.02 at a later date.
gasche (developer)
2014-12-27 10:23

Merged in 4.02.
doligez (administrator)
2015-02-21 00:22

There is a problem with this change: it breaks (at least) ocamlnet because the ocamlnet config script does this:
ocamlc -custom -o t tend.c
And with this patch, the C compiler puts its output in `t` instead of putting it in `tend.o` where the OCaml compiler expects it.

The long-term solution is for users to be aware that the order of arguments is important and to write instead:
ocamlc -custom tend.c -o t
I wouldn't mind doing this in trunk and documenting it properly ("sets the name of the output file for the next source file, or for the whole compilation if it appears on the command line later than all sources files") but for 4.02 I think it's too much incompatibility, so we should roll back.

We should also probably reset the -o argument as soon it has been used for one source file, since it doesn't make sense to overwrite a file you have just generated.

whitequark (developer)
2015-02-21 00:28

No, I think that the current behavior is actually wrong. There is no reason whatsoever to set the output file name for one of the intermediate build products. Indeed, the -o option should always set the filename for the whole compilation.
gasche (developer)
2015-02-21 14:12

I just reverted (4.02@15863) the 4.02 commit. The behavior in trunk is still problematic, so I'll revert it as well if don't converge on a solution.
doligez (administrator)
2015-02-23 19:12

@whitequark, I thought we had decided it would be nice to be able to do:

  ocamlopt -c -o /tmp/foo.o foo.c -o /tmp/bar.cmx

Or maybe that's overkill because no build system will do that. In that case, we still want -o to work if there's only one source file and the -c option is also given.
whitequark (developer)
2015-02-23 22:39

I think that's overkill and is very confusing. No other compiler in existence does that, and even few Unix tools do.

Indeed; with -c, that would qualify as the end result of compilation.

- Issue History
Date Modified Username Field Change
2014-06-30 11:30 yallop New Issue
2014-07-11 13:20 doligez Severity minor => feature
2014-07-11 13:20 doligez Status new => acknowledged
2014-10-23 22:14 whitequark Note Added: 0012423
2014-10-24 15:27 yallop Note Added: 0012429
2014-10-24 15:27 yallop Tag Attached: patch
2014-12-20 13:23 whitequark File Added: ocamlc-c-ocamlbuild.patch
2014-12-21 11:50 gasche Assigned To => whitequark
2014-12-21 11:50 gasche Status acknowledged => assigned
2014-12-21 11:50 gasche Note Added: 0012902
2014-12-21 13:02 whitequark File Deleted: ocamlc-c-ocamlbuild.patch
2014-12-21 13:02 whitequark File Added: ocamlc-c-o.patch
2014-12-21 13:02 whitequark Note Added: 0012907
2014-12-21 13:20 gasche Note Added: 0012908
2014-12-21 13:21 gasche Note Edited: 0012908 View Revisions
2014-12-21 13:21 gasche Note Edited: 0012908 View Revisions
2014-12-21 13:22 whitequark Note Added: 0012909
2014-12-21 19:05 whitequark Note Added: 0012920
2014-12-21 19:11 gasche Note Added: 0012921
2014-12-27 10:23 gasche Note Added: 0012993
2014-12-27 10:23 gasche Status assigned => resolved
2014-12-27 10:23 gasche Fixed in Version => 4.02.2+dev / +rc1
2014-12-27 10:23 gasche Resolution open => fixed
2015-02-21 00:22 doligez Note Added: 0013324
2015-02-21 00:22 doligez Status resolved => feedback
2015-02-21 00:22 doligez Resolution fixed => reopened
2015-02-21 00:22 doligez Target Version => 4.02.2+dev / +rc1
2015-02-21 00:28 whitequark Note Added: 0013325
2015-02-21 14:12 gasche Note Added: 0013326
2015-02-23 19:12 doligez Note Added: 0013328
2015-02-23 22:39 whitequark Note Added: 0013330
2015-04-02 18:00 doligez Fixed in Version 4.02.2+dev / +rc1 =>
2015-04-02 18:00 doligez Target Version 4.02.2+dev / +rc1 => 4.03.0+dev

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker