GTK + 3编译错误“找不到信号处理程序”是否使用-rdynamic进行编译?

时间:2019-08-17 12:17:34

标签: c++ gtk3

我正在使用Glade和GTK + 3制作GUI。我已经阅读了很多教程,阅读了很多论坛帖子,但仍然可以摆脱“ Gtk-WARNING **:14:50:06.794:找不到信号处理程序'on_window_main_destroy'。您使用-rdynamic进行编译吗?”我收到的每个信号都会发出警告。请帮忙。这个问题真的使我丧命!

我在Glade中制作了一个简单的GUI。它由主窗口,固定网格,两个标尺和两个与标尺连接的调整组成。我已将信号连接到主窗口“ destroy”和“ on_window_main_destroy”,并进行了调整:“值已更改-> on_adjustment_scale_exposure_value_changed”和“值已更改-> on_adjustment_scale_gain_value_changed”。

然后,我使用geany编写了代码。无论我如何尝试,每次运行程序时,都会收到所有信号的上述错误消息。

在Glade中,我尝试使用普通的另存为和另存为“ builder”文件。没什么。

我尝试了许多不同的g ++和gcc命令,没有区别。

滑行代码:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkAdjustment" id="adjustment_scale_exposure">
    <property name="lower">1</property>
    <property name="upper">1000</property>
    <property name="value">10</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
    <signal name="value-changed" handler="on_adjustment_scale_exposure_value_changed" swapped="no"/>
  </object>
  <object class="GtkAdjustment" id="adjustment_scale_gain">
    <property name="lower">1</property>
    <property name="upper">20</property>
    <property name="value">1</property>
    <property name="step_increment">1</property>
    <property name="page_increment">10</property>
    <signal name="value-changed" handler="on_adjustment_scale_gain_value_changed" swapped="no"/>
  </object>
  <object class="GtkWindow" id="window_main">
    <property name="width_request">1024</property>
    <property name="height_request">600</property>
    <property name="can_focus">False</property>
    <property name="border_width">5</property>
    <signal name="destroy" handler="on_window_main_destroy" swapped="no"/>
    <child>
      <placeholder/>
    </child>
    <child>
      <object class="GtkFixed">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkScale" id="scale_exposure">
            <property name="width_request">30</property>
            <property name="height_request">600</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="orientation">vertical</property>
            <property name="adjustment">adjustment_scale_exposure</property>
            <property name="inverted">True</property>
            <property name="round_digits">1</property>
            <property name="digits">0</property>
            <property name="value_pos">bottom</property>
          </object>
        </child>
        <child>
          <object class="GtkScale" id="scale_gain">
            <property name="width_request">30</property>
            <property name="height_request">600</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <property name="orientation">vertical</property>
            <property name="adjustment">adjustment_scale_gain</property>
            <property name="inverted">True</property>
            <property name="round_digits">1</property>
            <property name="value_pos">bottom</property>
          </object>
          <packing>
            <property name="x">30</property>
          </packing>
        </child>
      </object>
    </child>
  </object>
</interface>

书面代码:

#include "gtk/gtk.h"

GtkWidget *g_scale_exposure;
GtkAdjustment *g_adjustment_scale_exposure;
GtkWidget *g_scale_gain;
GtkAdjustment *g_adjustment_scale_gain;
GtkWidget *g_lbl_exposure;
GtkWidget *g_lbl_gain;

int main (int argc, char* argv[]){

    GtkBuilder *builder;
    GtkWidget *window;

    gtk_init(&argc, &argv);

    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, "main.glade", NULL);

    window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main"));
    gtk_builder_connect_signals(builder, NULL);

    g_scale_exposure = GTK_WIDGET(gtk_builder_get_object(builder, "scale_exposure"));
    g_scale_gain = GTK_WIDGET(gtk_builder_get_object(builder, "scale_gain"));
    g_adjustment_scale_exposure = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "adjustment_scale_exposure"));
    g_adjustment_scale_gain = GTK_ADJUSTMENT(gtk_builder_get_object(builder, "adjustment_scale_gain"));
    g_lbl_exposure = GTK_WIDGET(gtk_builder_get_object(builder, "lbl_exposure"));
    g_lbl_gain = GTK_WIDGET(gtk_builder_get_object(builder, "lbl_gain"));

    g_object_unref(builder);

    gtk_widget_show(window);
    gtk_main();

    return 0;
}

void on_window_main_destroy(){
    gtk_main_quit();
}

void on_adjustment_scale_exposure_value_changed(GtkAdjustment *adjustment_scale_exposure, gpointer data){
    int scaleValue = gtk_adjustment_get_value(GTK_ADJUSTMENT(g_adjustment_scale_exposure));

    printf("moi, %d\n", scaleValue);

}

void on_adjustment_scale_gain_value_changed(GtkAdjustment *adjustment_scale_gain, gpointer data){
    float scaleValue = gtk_adjustment_get_value(GTK_ADJUSTMENT(g_adjustment_scale_gain));
    printf("moi2, %f\n", scaleValue);

}

g ++代码:

g++ -rdynamic -Wall  normiApiTestiGlade2.cpp -o runme `pkg-config --cflags --libs gtk+-3.0 gmodule-2.0`

预期结果将是在连接信号的情况下运行GUI。现在,GUI启动,我可以移动滑块,但是没有任何改变(GUI中除外)。

警告: (runme:18098):Gtk-警告**:15:09:26.660:找不到信号处理程序'on_window_main_destroy'。您使用-rdynamic进行编译了吗?

(runme:18098):Gtk-警告**:15:09:26.660:找不到信号处理程序'on_adjustment_scale_gain_value_changed'。您使用-rdynamic进行编译了吗?

(runme:18098):Gtk-警告**:15:09:26.660:找不到信号处理程序'on_adjustment_scale_exposure_value_changed'。您使用-rdynamic进行编译了吗?

1 个答案:

答案 0 :(得分:1)

gtk_builder_connect_signals包含您需要的所有信息。

  

在未显式添加符号的情况下; 它使用GModule的自省功能...来查看应用程序的符号表...

     

如果您依靠GModule支持在符号表中查找回调,则应注意以下详细信息:

     

在为Windows编译应用程序时,必须使用G_MODULE_EXPORT声明信号回调,否则它们将不会放在符号表中。在Linux和Unices上,这不是必需的。相反,应使用-Wl,-export-dynamic CFLAGS编译应用程序,并针对gmodule-export-2.0进行链接。

您必须将-Wl,--export-dynamic(原文如此)传递给编译器。