GNOME Bugzilla – Bug 638871
valac -o command parameter does not work with -c
Last modified: 2018-05-22 13:50:50 UTC
Valac -o parameter (output file) works only if there is no -c parameter. Following example valac hello.vala -c -o myobj produces hello.vala.o instead of myobj. The issue is present with valac 0.10 0.11
It's not honoured with -C either. I'm seeing this with Vala 0.12.0 (from the Ubuntu ppa). This makes it extremely hard to use a build system with vala.
I think the erroneous logic is in valasourcefile.val, get_csource_filename(): public string get_csource_filename () { if (csource_filename == null) { if (context.run_output) { csource_filename = context.output + ".c"; } else if (context.ccode_only || context.save_csources) { csource_filename = "%s%s.c".printf (get_destination_directory (), get_basename ()); } else { // temporary file csource_filename = "%s%s.vala.c".printf (get_destination_directory (), get_basename ()); } } return csource_filename; } It looks like the -o option is only used when run_output is specified, and everything else uses autogenerated filenames based on the basename. My gut instinct is that the -o option should *always* specify the output filename, and the autogeneration should only happen if no output filename is specified --- this doesn't violate Principle Of Least Surprise. I suspect very few people have noticed this as most users of vala will be using -d instead of -o.
(In reply to comment #0) > The issue is present with valac 0.10 0.11 I have the same problem with Vala 0.13.0
(In reply to comment #2) > I suspect very few people have noticed this as most users of vala will be using > -d instead of -o. -d also doesn't work with -c option Object file is always placed in the current directory (tested with 0.13.0).
Created attachment 207756 [details] [review] Fixes -o and -d switches when used with -d
Created attachment 371336 [details] [review] compiler: Fix handling of -o and -d in combination with -c When compiling to object files, there are a few things to keep in mind: - gcc doesn't provide a --directory switch itself so valac has to simulate that using -o. - For multiple source files, gcc cannot use both -o and -c, the same applies to valac. (maybe vala should detect that beforehand though.) So for example valac -c foo.vala bar.vala works as expected but valac -c -d outdir foo.vala bar.vala will generate a warning from gcc as the -o option has to be used.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/154.