即使我命令带了参数,args始终是NULL,不解阿,请教了
#include <gnome.h>
struct poptOption options[] = {
{
"greet",
'g',
POPT_ARG_NONE,
FALSE, <-- 这必须给个变量,因为POPT_ARG_NONE是个开关值,如果开了,-g 则为TRUE,否则为FALSE
0,
"Say hello to specific people listed on the command line",
NULL
},
{
NULL,
'\0',
0,
NULL,
0,
NULL,
NULL
}
};
static char* PACKAGE = "base4";
static char* VERSION = "0.4";
static char* GNOMELOCALEDIR = "~/learning";
int main (int argc, char *argv[])
{
GtkWidget *app = NULL;
poptContext pctx;
char** args ;
bindtextdomain(PACKAGE, GNOMELOCALEDIR);
textdomain(PACKAGE);
gnome_init_with_popt_table(PACKAGE, VERSION, argc, argv, options, 0, &pctx);
args = poptGetArgs(pctx);
if (args ==NULL) {
g_error("args is null");
}
poptFreeContext(pctx);
gtk_main ();
return 0;
}
xiao-ye@xiao-ye-laptop:~/learning$ ./base4
** ERROR **: args is null
aborting...
忽略 (core dumped)
xiao-ye@xiao-ye-laptop:~/learning$ ./base4 -g
** ERROR **: args is null
aborting...
忽略 (core dumped)