After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 638871 - valac -o command parameter does not work with -c
valac -o command parameter does not work with -c
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: general
0.10.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-06 22:18 UTC by Anatol Pomozov
Modified: 2018-05-22 13:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixes -o and -d switches when used with -d (3.33 KB, patch)
2012-02-16 11:53 UTC, Simon Werbeck
none Details | Review
compiler: Fix handling of -o and -d in combination with -c (3.16 KB, patch)
2018-04-24 18:30 UTC, Rico Tzschichholz
none Details | Review

Description Anatol Pomozov 2011-01-06 22:18:26 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
Comment 1 David given 2011-04-21 23:17:13 UTC
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.
Comment 2 David given 2011-04-21 23:36:08 UTC
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.
Comment 3 Andrzej Bieniek 2011-07-03 15:29:09 UTC
(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
Comment 4 Andrzej Bieniek 2011-07-03 15:36:07 UTC
(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).
Comment 5 Simon Werbeck 2012-02-16 11:53:10 UTC
Created attachment 207756 [details] [review]
Fixes -o and -d switches when used with -d
Comment 6 Rico Tzschichholz 2018-04-24 18:30:35 UTC
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.
Comment 7 GNOME Infrastructure Team 2018-05-22 13:50:50 UTC
-- 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.