6

下面的编译警告对我来说不是很清楚,除了弃用警告之外,还有 valadoc 中方法的签名:

http://valadoc.org/#!api=gstreamer-1.0/Gst

没有显示其他方法签名。

另一个警告更加模糊。

max@max-ubuntu:~/mdev/cr valac --pkg gstreamer-0.10 gstpipe.vala
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:在函数“application_message”中:
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:64:2:警告:传递 '_gst_structure_copy0' ​​的参数 1 会从指针目标类型中丢弃 'const' 限定符 [默认启用]
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:26:17:注意:预期为“gpointer”,但参数类型为“const struct GstStructure *”
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:82:9:警告:分配从指针目标类型中丢弃“const”限定符[默认启用]
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:在函数'main'中:
/home/max/dev/main-sandbox/cr/gstpipe.vala.c:173:2:警告:'g_type_init' 已弃用(在 /usr/include/glib-2.0/gobject/gtype.h:669 声明) [-Wdeprecated-declarations]

使用消费税;


无效应用程序消息(Gst.Bus 总线,Gst.Message 消息){

        var s = msg.get_structure();

        如果(s == null)
            返回;

        字符串 msgtype = s.get_name();

        如果(msgtype!=“级别”)
            返回;

        GLib.Value rms = s.get_value("rms");
        //GLib.Value st = s.get_value("stream-time");

        GLib.DateTime 现在 = 新 GLib.DateTime.now_local();

        var sec = now.to_unix();
        var msec = (sec * 1000) + now.get_microsecond();        

        var z = rms.strdup_contents();

        //z = z.replace("{", "[").replace("}", "]");

        stdout.printf("%ld, %s \n", (long) msec, z);
}


无效的主要(字符串[] args){

    Gst.init(参考参数);

    尝试 {

        var pipeline = Gst.parse_launch(
          “pulsesrc 设备=\”alsa_input.usb-046d_08c9_674634A4-02-U0x46d0x8c9.analog-mono\“!”+
          "级别名称=wavelevel 间隔=10000000 !" +
          “wavenc!文件接收器位置=audioz.wav”
        );

        var bus = pipeline.get_bus();

        bus.add_signal_watch();
        bus.message.connect(application_message);

        // 设置管道状态为 PLAYING
        pipeline.set_state (State.PLAYING);

        // 创建并启动 GLib 主循环
        新的 MainLoop ().run ();        
    }
    捕获(错误 e){
        print("%s\n", e.message);
    }
}
4

1 回答 1

13

You can generally ignore warnings from the C compiler when using Vala. Vala has better information than the C compiler, so it knows certain things are valid when the C compiler has no way of knowing that. Unfortunately we can't just add casts everywhere since there are situations where we can't generate a valid cast (and, what's more, no way to know what those situations are).

The final warning, about g_type_init being deprecated, is because g_type_init is no longer necessary as of glib 2.36. You can get rid of that warning by passing --target-glib=2.36 (or any later version of glib) to valac, but be warned that the generated code may no longer work with older versions of glib.

TBH, I often just pass -X -w to valac to get the C compiler to be quiet. Occasionally I miss a useful warning, but it gets rid of a lot of useless warnings.

于 2013-10-19T17:35:05.263 回答