我试图从C代码调用一个八度函数,但问题是为什么在八度mkoctfile --mex addition_GUI.c
运行此命令时出现错误addition_GUI.c:1:20: fatal error: gtk/gtk.h: No such file or directory compilation terminated.
我可以从C代码调用八度函数但是当我尝试使用GTK + 2从代码代码调用时发生错误。
#include<gtk/gtk.h>
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *in[2], *out[1];
in[0] = mxCreateDoubleScalar(1);
in[1] = mxCreateDoubleScalar(2);
mexCallMATLAB(1, out, 2, in, "addition");
mexCallMATLAB(0, NULL, 1, out, "disp");
mxDestroyArray(in[0]);
mxDestroyArray(in[1]);
mxDestroyArray(out[0]);
}
void static call(GtkWidget *widget,gpointer data)
{
g_print("\n%s\n",gtk_entry_get_text(GTK_ENTRY(data)));
gint a=3;
gint b=2;
gint x;
x=a+b;
char y[4];
sprintf(y, "%d", x);
gtk_entry_set_text(GTK_ENTRY(data),y);
}
int main(int agrc, char *agrv[])
{
gtk_init(&agrc,&agrv);
GtkWidget *entry,*window,*button,*hbox;
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window,"delete-event",G_CALLBACK(gtk_main_quit),NULL);
hbox=gtk_hbox_new(0,0);
gtk_container_add(GTK_CONTAINER(window),hbox);
button=gtk_button_new_with_mnemonic("ADD");
entry=gtk_entry_new();
const char* sum="3+2";
gtk_entry_set_text(GTK_ENTRY(entry),sum);
g_signal_connect(button,"clicked",G_CALLBACK(call),entry);
g_signal_connect(entry,"activate",G_CALLBACK(call),entry);
gtk_box_pack_start(GTK_BOX(hbox),button,0,0,0);
gtk_box_pack_start(GTK_BOX(hbox),entry,0,0,0);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
答案 0 :(得分:0)
您需要以某种方式指定包含目录和库以再次链接 - (pkg-config --libs --cflags gtk+-2.0
返回的那些)。