one question about glib

View: New views
3 Messages — Rating Filter:   Alert me  

one question about glib

by Leao :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, List!
Recently, I am writing a little program with gtk+ on win32 platform. In this program I use g_spawn_async_with_pipes(NULL,cmd_line,NULL,G_SPAWN_SEARCH_PATH,NULL,NULL,NULL,NULL,&std_out,NULL,NULL); to call gcc and as a result the command line has executed successfully .However when I use g_io_channel_reda_chars(channel,out,-1,&bytes_read,NULL) to get the standard out stored in out, it turns out to be wrong.Here is my code :

   gchar *cmd_line[] = {"gcc","-o","temp.exe","temp.c","-mms-bitfields", "-lgtk-win32-2.0", "-lgdk-win32-2.0", "-latk-1.0", "-lgdk_pixbuf-2.0", "-lpangowin32-1.0", "-lgdi32" ,"-lpango-1.0" ,"-lgobject-2.0" ,"-lgmodule-2.0", "-lglib-2.0" ,"-lintl"};
    gchar out[1024];
    GIOChannel *channel;
    gint std_out = 0;
    gint bytes_read;        g_spawn_async_with_pipes(NULL,cmd_line,NULL,G_SPAWN_SEARCH_PATH,NULL,NULL,NULL,NULL,&std_out,NULL,NULL);
    channel = g_io_channel_unix_new(std_out);
    g_io_channel_read_chars(channel,out,-1,&bytes_read,NULL);

If I want to get the standard out ,what should I do?
 Any info is appreciated ! :)
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@...
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: one question about glib

by Tor Lillqvist :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> However when I use g_io_channel_reda_chars(channel,out,-1,&bytes_read,NULL) to get the standard out stored in out, it turns out to be wrong.

In what way is it wrong? A successful run of gcc to compile and link a
program produces no output.

>   gchar *cmd_line[] = {"gcc","-o","temp.exe","temp.c","-mms-bitfields", "-lgtk-win32-2.0", "-lgdk-win32-2.0", "-latk-1.0", "-lgdk_pixbuf-2.0", "-lpangowin32-1.0", "-lgdi32" ,"-lpango-1.0" ,"-lgobject-2.0" ,"-lgmodule-2.0", "-lglib-2.0" ,"-lintl"};

You forget the terminating NULL element in the argv.

Also, are you sure that gcc will find the GTK+ headers and libraries?
You don't pass any -I and -L flags. If you have copied the GTK+ stack
headers and libraries into your mingw installation (so that gcc and ld
will find them without any -I and -L options), I would say that is a
bad idea. Better to keep stuff from different distributions separate
and not copy headers and libraries around.

And in general, instead of manually constructing (or hardcoding) the
correct -I, -L and -l options, just use pkg-config.

--tml
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@...
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Parent Message unknown Re: one question about glib

by Tor Lillqvist :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

When replying to a message on a mailing list (especially one about
Open Source software), please reply to the mailing list, not to the
message sender. The very point with public mailing lists is that
discussion threads are kept public and archived for others to see. I
am adding gtk-app-devel-list back to Cc.

> The development environment configutation was correct and the output file
> can execute successuflly.

Can you explain how that can be true, i.e. where did you install
(copy) the headers and import libraries of the GTK+ stack? Just out of
interest.

> But  the character string out returned by
> g_io_channel_read_chars(channel,out,-1,&bytes_read,NULL) was empty

g_io_channel_read_chars() doesn't return a string. It returns a
GIOStatus. But yeah, I know what you mean. I hope...

As I said, a successfull run of gcc to compile and link a single
source file with no warnings doesn't print anything to standard
output. Just run the command manually and you will see that nothing is
printed. So why does it surprise you that nothing is written to the
standard output pipe then?

By the way, there is at least one serious problem in your code. You
pass -1 as the size of the buffer to g_io_channel_read_chars(). So of
course there will never be anything stored in the buffer. But even if
one fixes this and passes sizeof(out) instead, nothing is read, as
nothing is written. It would be better to use
g_io_channel_read_to_end() in this case, though.

> nothing returned from this function.

Of course the function returns something. It is impossible in C for a
non-void function to not return anything. But yeah, I am just teasing
you. Sorry for that.

> Which functions should I use ?

Well, unless you want to do asynchronous stuff or other niceties,
what's wrong with system() or popen()?

--tml
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@...
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list