ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am new at programming Gtk gnome linux C application, and I am trying to learn from some source reagind and online gnome documentation but I can't do it because this is in my opinion very poor and bad. I have a problem understanding this following source: after creating a GObject of GApplication type, how can this main function call other parts of programs? (This is from gedit source) I learnt that GApplication doesn't include any pointer to some code.
/*
* gedit.c
* This file is part of gedit
*
* Copyright (C) 2005 - Paolo Maggi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
/* This code must live in gedit.exe, not in libgedit.dll, since the whole
* point is to find and load libgedit.dll.
*/
static gboolean
gedit_w32_load_private_dll (void)
{
gchar *dllpath;
gchar *prefix;
if (prefix != NULL)
{
/* Instead of g_module_open () it may be possible to do any of the
* following:
* A) Change PATH to "${dllpath}/lib/gedit;$PATH"
* B) Call SetDllDirectory ("${dllpath}/lib/gedit")
* C) Call AddDllDirectory ("${dllpath}/lib/gedit")
* But since we only have one library, and its name is known, may as well
* use gmodule.
*/
dllpath = g_build_filename (prefix, "lib", "gedit", "libgedit.dll", NULL);
g_free (prefix);
libgedit_dll = g_module_open (dllpath, 0);
if (libgedit_dll == NULL)
{
g_printerr ("Failed to load '%s': %s\n",
dllpath, g_module_error ());
}
g_free (dllpath);
}
if (libgedit_dll == NULL)
{
libgedit_dll = g_module_open ("libgedit.dll", 0);
if (libgedit_dll == NULL)
{
g_printerr ("Failed to load 'libgedit.dll': %s\n",
g_module_error ());
}
}
status = g_application_run (G_APPLICATION (app), argc, argv);
/* Break reference cycles caused by the PeasExtensionSet
* for GeditAppActivatable which holds a ref on the GeditApp
*/
g_object_run_dispose (G_OBJECT (app));
Please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.
The Gtk application is instantiated and run from these lines...
The complete GApplications reference should be very helpful and lead you to similar pages for each class and their properties and use.
Please become familiar with the structure of GApplications and the online documentation - it is complete and well indexed and linked. If there is a specific part of it that you do not understand please describe your specific difficulty and we will try to help further.
Last edited by astrogeek; 07-03-2017 at 12:29 PM.
Reason: Forgot g_object_new link
My problem is where this source file can call another; if it not call another object (compiled) file then it wiil not be linked.
How from this source everyone will obtain Gedit?
Please reply!
Generally you use a makefile. just cd to gedit source directory than run ./configure if you have all the dependencies installed a makefile should be created than run ./make this should be compile and link it.
However if all else fails read directions should be a readme file.
Generally you use a makefile. just cd to gedit source directory than run ./configure if you have all the dependencies installed a makefile should be created than run ./make this should be compile and link it.
However if all else fails read directions should be a readme file.
Read carefully: this is not a compile error, but a misunderstand in learning. I am not trying to use gnuautotools but only reading source.
In the source there is that main function that will become entry point of final executable; but how is possible linking whole program (gedit)? What is the function that call from main the remaining of program?
Read carefully: this is not a compile error, but a misunderstand in learning. I am not trying to use gnuautotools but only reading source.
In the source there is that main function that will become entry point of final executable; but how is possible linking whole program (gedit)? What is the function that call from main the remaining of program?
At compile time and link time glib.h, gedit-app.h, and everything they define and include is in scope and is used to build and link the necessary parts of the application. There are various flags and compile-time options mentioned in the above links which determine when static executables, dynamically linked executables and runtime inter-process communication (D-Bus) are used.
Everything at runtime is handled by g_application_run(...), please read the above linked pages for documentation specific to that function. Main is the entry point for all C/C++ programs, and it includes the call to g_application_run(...), which takes a pointer to the application object as an argument, to execute the application.
Code:
main () {
app = g_object_new(...)
g_application_run(app)
exit
}
As Mill J has pointed out, you would generally build with a Makefile configured for the application, whether generated by autotools or of some other origin. The point being that the Makefile would define various compile and link options.
For a complete overview of Gtk application structure, have a look at this page, Overview of GTK+ and its Libraries and this one, GNOME application development overview, for all the details of designing and building Gtk applications, how the libraries interact and the various options available to you.
Last edited by astrogeek; 07-04-2017 at 12:49 AM.
Reason: added explicit pointer reference
At compile time and link time glib.h, gedit-app.h, and everything they define and include is in scope and is used to build and link the necessary parts of the application. There are various flags and compile-time options mentioned in the above links which determine when static executables, dynamically linked executables and runtime inter-process communication (D-Bus) are used.
Everything at runtime is handled by g_application_run(...), please read the above linked pages for documentation specific to that function. Main is the entry point for all C/C++ programs, and it includes the call to g_application_run(...), which takes a pointer to the application object as an argument, to execute the application.
Code:
main () {
app = g_object_new(...)
g_application_run(app)
exit
}
As Mill J has pointed out, you would generally build with a Makefile configured for the application, whether generated by autotools or of some other origin. The point being that the Makefile would define various compile and link options.
For a complete overview of Gtk application structure, have a look at this page, Overview of GTK+ and its Libraries and this one, GNOME application development overview, for all the details of designing and building Gtk applications, how the libraries interact and the various options available to you.
Okay, I knew so!
But when main function call g_application_run how can it call the remaining program?
There is no pointer to some function, maybe the library has internally some symbol name for call another function??
Please read and try to understand the Gtk application reference material already linked.
Quote:
Originally Posted by Unaaaaab
Okay, I knew so!
But when main function call g_application_run how can it call the remaining program?
There is no pointer to some function, maybe the library has internally some symbol name for call another function??
Yes there is a pointer to the application object...
Code:
GeditApp *app
app = g_object_new(...)
...passed to the function which knows the interface offered by that object...
Code:
g_application_run(app)
I understand that learning a new programming paradigm or library structure can be time consuming and requires effort, but you must make that effort yourself, we cannot do that for you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.