Author Topic: GTK+ template  (Read 13519 times)

gege2061

  • Guest
GTK+ template
« on: November 09, 2006, 10:47:53 am »
Hi,

First, excuse me for my (very) bad English :(

I developed a GTK+ template for C::B, it work with RC1 but with last Nightly builds (07 November) it does not appear in New Projects dialog box :(

Here files based on the Qt template :

share/CodeBlocks/templates/gtk.cbp
Code
<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_project_file>
<CodeBlocks_project_file>
<FileVersion major="1" minor="1"/>
<Project>
<Option title="GTK+ application"/>
<Option makefile="Makefile"/>
<Build>
<Target title="default">
<Option type="0"/>
<Option parameters=""/>
<Option includeInTargetAll="1"/>
<Option projectCompilerOptionsRelation="3"/>
<Option projectLinkerOptionsRelation="3"/>
<Option projectIncludeDirsRelation="3"/>
<Option projectLibDirsRelation="3"/>
<Compiler>
<Add option="-mno-cygwin"/>
<Add option="-mms-bitfields"/>
<Add directory="C:\Program Files\CodeBlocks\include\gtk-2.0"/>
<Add directory="C:\Program Files\CodeBlocks\lib\gtk-2.0\include"/>
<Add directory="C:\Program Files\CodeBlocks\include\atk-1.0"/>
<Add directory="C:\Program Files\CodeBlocks\include\pango-1.0"/>
<Add directory="C:\Program Files\CodeBlocks\include\glib-2.0"/>
<Add directory="C:\Program Files\CodeBlocks\include\glib-2.0\glib"/>
<Add directory="C:\Program Files\CodeBlocks\lib\glib-2.0"/>
<Add directory="C:\Program Files\CodeBlocks\lib\glib-2.0\include"/>
<Add directory="C:\Program Files\CodeBlocks\include\cairo"/>
</Compiler>
<Linker>
<Add option="-limm32"/>
<Add option="-lshell32"/>
<Add option="-lole32"/>
<Add option="-luuid"/>
<Add library="C:\Program Files\CodeBlocks\lib\glib-2.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\pangocairo-1.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\pangowin32-1.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\libatk-1.0.dll.a"/>
<Add library="C:\Program Files\CodeBlocks\lib\gdk_pixbuf-2.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\gdk-win32-2.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\pango-1.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\gmodule-2.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\gobject-2.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\gthread-2.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\gtk-win32-2.0.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\cairo.lib"/>
<Add library="C:\Program Files\CodeBlocks\lib\pangoft2-1.0.lib"/>
</Linker>
</Target>
</Build>
</Project>
</CodeBlocks_project_file>

share/CodeBlocks/templates/gtk.template
Code
<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_template_file>
<CodeBlocks_template_file>
<Template name="GTKapp" title="GTK Application" category="GUI" bitmap="gtklogo.png">
<FileSet name="s" title="Default">
<File source="gtk-main.c" destination="main.c"/>
</FileSet>
<Option name="GTK Application">
<Project file="gtk.cbp"/>
</Option>
</Template>
</CodeBlocks_template_file>

share/CodeBlocks/templates/gtk.template
Code
#include <stdlib.h>
#include <gtk/gtk.h>


static void helloWorld (GtkWidget *wid, GtkWidget *win)
{
  GtkWidget *dialog = NULL;

  dialog = gtk_message_dialog_new (GTK_WINDOW (win), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "Hello World!");
  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
  gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);
}


int main (int argc, char *argv[])
{
  GtkWidget *button = NULL;
  GtkWidget *win = NULL;
  GtkWidget *vbox = NULL;

  /* Initialize GTK+ */
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL);
  gtk_init (&argc, &argv);
  g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL);

  /* Create the main window */
  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (win), 8);
  gtk_window_set_title (GTK_WINDOW (win), "Hello World");
  gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  gtk_widget_realize (win);
  g_signal_connect (win, "destroy", gtk_main_quit, NULL);

  /* Create a vertical box with buttons */
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (win), vbox);

  button = gtk_button_new_from_stock (GTK_STOCK_DIALOG_INFO);
  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (helloWorld), (gpointer) win);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  g_signal_connect (button, "clicked", gtk_main_quit, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

  /* Enter the main loop */
  gtk_widget_show_all (win);
  gtk_main ();
  return 0;
}

Where is mistake ?

Thanks ;)

[attachment deleted by admin]

Offline Game_Ender

  • Lives here!
  • ****
  • Posts: 551
Re: GTK+ template
« Reply #1 on: November 09, 2006, 02:50:49 pm »
The nightly builds use wizards now, I am not sure if templates still work.

gege2061

  • Guest
Re: GTK+ template
« Reply #2 on: November 09, 2006, 03:31:36 pm »
The nightly builds use wizards now, I am not sure if templates still work.
Ok, I thought that it was optional.
I just forgot to complete share/CodeBlocks/templates/wizard/config.script file

Now, GTK project appears in the window but an error occurs.

I work that and I will post the result, if that interests you ;)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: GTK+ template
« Reply #3 on: November 09, 2006, 03:55:50 pm »
Now, GTK project appears in the window but an error occurs.
What error?
And BTW: If you want to, you can create a new wizard that is compatible to the new scripted wizard plugin. It should be quite easy - you can take e.g. the GLUT wizard as template.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: GTK+ template
« Reply #4 on: November 09, 2006, 10:18:53 pm »
[...]you can create a new wizard that is compatible to the new scripted wizard plugin. [...]
Done that in SVN. ;-)
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

gege2061

  • Guest
Re: GTK+ template
« Reply #5 on: November 10, 2006, 10:32:21 am »
What error?
And BTW: If you want to, you can create a new wizard that is compatible to the new scripted wizard plugin. It should be quite easy - you can take e.g. the GLUT wizard as template.
With regards, Morten.
Indeed, it's very easy :D

Done that in SVN. ;-)
Ok, I test it under Windows and Linux and commit ;)

gege2061

  • Guest
Re: GTK+ template
« Reply #6 on: November 10, 2006, 02:26:04 pm »
Done that in SVN. ;-)
ok you created the template !
Here I that I made (run under Windows and Linux) :
Code
////////////////////////////////////////////////////////////////////////////////
//
// GTK project wizard
//
////////////////////////////////////////////////////////////////////////////////

// globals
GtkPathDefault    <- _T("$(#gtk)");
GtkPathDefaultInc <- _T("$(#gtk.include)");
GtkPathDefaultLib <- _T("$(#gtk.lib)");
GtkPath <- _T("");

function BeginWizard()
{
    local intro_msg = _T("Welcome to the new GTK project wizard!\n" +
                         "This wizard will guide you to create a new GTK project\n" +
                         "using the GTK cross-platform GUI toolkit\n\n" +
                         "When you're ready to proceed, please click \"Next\"...");

    local gtkpath_msg = _T("Please select the location of GTK on your computer.\n" +
                           "This is the top-level folder where GTK was installed.\n" +
                           "To help you, this folder must contain the subfolders\n" +
                           "\"include\" and \"lib\".");

    Wizard.AddInfoPage(_T("GtkIntro"), intro_msg);
    Wizard.AddProjectPathPage();
    Wizard.AddGenericSelectPathPage(_T("GtkPath"), gtkpath_msg, _T("GTK's location:"), GtkPathDefault);
    Wizard.AddCompilerPage(_T(""), _T("gcc*"), true, true);
}

////////////////////////////////////////////////////////////////////////////////
// Gtk's path page
////////////////////////////////////////////////////////////////////////////////

function OnLeave_GtkPath(fwd)
{
    if (fwd)
    {
        local dir         = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
        local dir_nomacro = VerifyDirectory(dir);

        if (dir_nomacro.IsEmpty())
            return false;

        // verify include dependencies
        local dir_nomacro_inc = GetCompilerIncludeDir(dir, GtkPathDefault, GtkPathDefaultInc);
        if (dir_nomacro_inc.IsEmpty())
            return false;
        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))
            return false;

        // verify library dependencies
        local dir_nomacro_lib = GetCompilerLibDir(dir, GtkPathDefault, GtkPathDefaultLib);
        if (dir_nomacro_lib.IsEmpty())
            return false;
        if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-2.0"), _T("GTK's")))
            return false;


        GtkPath = dir; // Remember the original selection.

        local is_macro = _T("");

        // try to resolve the include directory as macro
        is_macro = GetCompilerIncludeMacro(dir, GtkPathDefault, GtkPathDefaultInc);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real inc path we had computed instead
            GtkPathDefaultInc = dir_nomacro_inc;
        }

        // try to resolve the library directory as macro
        is_macro = GetCompilerLibMacro(dir, GtkPathDefault, GtkPathDefaultLib);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real lib path we had computed instead
            GtkPathDefaultLib = dir_nomacro_lib;
        }
    }
    return true;
}

// return the files this project contains
function GetFilesDir()
{
    return _T("gtk/files");
}

// setup the already created project
function SetupProject(project)
{
    project.AddIncludeDir(GtkPathDefaultInc);
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("cairo"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0"));
    // Notice GtkPathDefault*Lib* at some positions. This is correct as of 2.8.20
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("pango-1.0"));
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0")  + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));
   

    project.AddLibDir(GtkPathDefaultLib);

    // add link libraries
    project.AddLinkLib(_T("gtk-win32-2.0"));
    project.AddLinkLib(_T("gobject-2.0"));
    project.AddLinkLib(_T("glib-2.0"));

    // Notice: there are more libs required as the app gets more complex, e.g.:
    // pangocairo-1.0.lib, pangocairo-1.0.lib, libatk-1.0.dll.a,
    // gdk_pixbuf-2.0.lib, gdk-win32-2.0.lib,  pango-1.0.lib,
    // gmodule-2.0.lib,    gthread-2.0.lib,    cairo.lib,
    // pangoft2-1.0.lib    (...)

    // enable compiler warnings (project-wide)
    WarningsOn(project, Wizard.GetCompilerID());

    project.AddCompilerOption(_T("-mms-bitfields"));

    // Debug
    local target = project.GetBuildTarget(Wizard.GetDebugName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
        target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        // enable generation of debugging symbols for target
        DebugSymbolsOn(target, Wizard.GetCompilerID());
    }

    // Release
    target = project.GetBuildTarget(Wizard.GetReleaseName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttExecutable); // ttExecutable: no console
        target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        // enable optimizations for target
        OptimizationsOn(target, Wizard.GetCompilerID());
    }

    return true;
}

Thank you for your exelent work ;)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: GTK+ template
« Reply #7 on: November 11, 2006, 04:58:07 pm »
Here I that I made (run under Windows and Linux) :
[...]
Mmmmh... I don't see a difference to the one that is in SVN? Am I missing something? Did you say you've adopted it to work under Linux?!

Thank you for your exelent work ;)
You're welcome! :-) Still: It's untested under Linux and older/newer version of GTK. There are modifications required to accomplish that.

With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

gege2061

  • Guest
Re: GTK+ template
« Reply #8 on: November 11, 2006, 06:42:44 pm »
Sorry, it was not the good file :(
Code
////////////////////////////////////////////////////////////////////////////////
//
// GTK+ project wizard
//
////////////////////////////////////////////////////////////////////////////////

// globals
GtkPathDefault    <- _T("$(#gtk)");
GtkPathDefaultInc <- _T("$(#gtk.include)");
GtkPathDefaultLib <- _T("$(#gtk.lib)");
GtkPath <- _T("");

function BeginWizard()
{
    local intro_msg = _T("Welcome to the new GTK+ project wizard!\n\n" +
                         "This wizard will guide you to create a new project\n" +
                         "using the GTK+.\n\n" +
                         "When you're ready to proceed, please click \"Next\"...");

    local gtkpath_descr = _T("Please select the location of GTK+ on your computer.\n" +
                             "This is the top-level folder where GTK+ was installed (unpacked).\n" +
                             "To help you, this folder must contain the subfolders\n" +
                             "\"include\" and \"lib\".");

    Wizard.AddInfoPage(_T("GtkIntro"), intro_msg);
    Wizard.AddProjectPathPage();
    Wizard.AddGenericSelectPathPage(_T("GtkPath"), gtkpath_descr, _T("Please select GTK+'s location:"), GtkPathDefault);
    Wizard.AddCompilerPage(_T(""), _T("*"), true, true);
}

////////////////////////////////////////////////////////////////////////////////
// GTK+'s path page
////////////////////////////////////////////////////////////////////////////////

function OnLeave_GtkPath(fwd)
{
    if (fwd)
    {
        local dir         = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
        local dir_nomacro = VerifyDirectory(dir);

        if (dir_nomacro.IsEmpty())
            return false;

        // verify include dependencies
        local dir_nomacro_inc = GetCompilerIncludeDir(dir, GtkPathDefault, GtkPathDefaultInc);
        if (dir_nomacro_inc.IsEmpty())
            return false;
        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH + _T("gtk"), _T("gtk.h"), _T("GTK+'s include"))) return false;

        // verify library dependencies
        local dir_nomacro_lib = GetCompilerLibDir(dir, GtkPathDefault, GtkPathDefaultLib);
        if (dir_nomacro_lib.IsEmpty())
            return false;

        if (PLATFORM == PLATFORM_MSW)
        {
            if (!VerifyLibFile(dir_nomacro_lib, _T("libgtk-win32-2.0.dll"), _T("GTK+'s"))) return false;
        }
        else
        {
            if (!VerifyLibFile(dir_nomacro_lib, _T("libgtk-x11-2.0.la"), _T("GTK+'s"))) return false;
        }


        GtkPath = dir; // Remember the original selection.

        local is_macro = _T("");

        // try to resolve the include directory as macro
        is_macro = GetCompilerIncludeMacro(dir, GtkPathDefault, GtkPathDefaultInc);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real inc path we had computed instead
            GtkPathDefaultInc = dir_nomacro_inc;
        }

        // try to resolve the library directory as macro
        is_macro = GetCompilerLibMacro(dir, GtkPathDefault, GtkPathDefaultLib);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real lib path we had computed instead
            GtkPathDefaultLib = dir_nomacro_lib;
        }
    }
    return true;
}

// return the files this project contains
function GetFilesDir()
{
    return _T("gtk/files");
}

// setup the already created project
function SetupProject(project)
{
    // set project options
    project.AddIncludeDir(GtkPathDefaultInc);
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("cairo"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("pango-1.0"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0"));
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("glib"));
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0"));

    project.AddLibDir(GtkPathDefaultLib);

    // add link libraries
    if (PLATFORM == PLATFORM_MSW)
    {
        project.AddLinkLib(_T("glib-2.0"));
        project.AddLinkLib(_T("pangocairo-1.0"));
        project.AddLinkLib(_T("pangowin32-1.0"));
        project.AddLinkLib(_T("libatk-1.0"));
        project.AddLinkLib(_T("gdk_pixbuf-2.0"));
        project.AddLinkLib(_T("gdk-win32-2.0"));
        project.AddLinkLib(_T("pango-1.0"));
        project.AddLinkLib(_T("gmodule-2.0"));
        project.AddLinkLib(_T("gobject-2.0"));
        project.AddLinkLib(_T("gthread-2.0"));
        project.AddLinkLib(_T("gtk-win32-2.0"));
        project.AddLinkLib(_T("cairo"));
        project.AddLinkLib(_T("pangoft2-1.0"));

        project.AddCompilerOption(_T("-mno-cygwin"));
        project.AddCompilerOption(_T("-mms-bitfields"));

        project.AddLinkerOption(_T("-limm32"));
        project.AddLinkerOption(_T("-lshell32"));
        project.AddLinkerOption(_T("-lole32"));
        project.AddLinkerOption(_T("-luuid"));
    }
    else
    {
        project.AddLinkLib(_T("gtk-x11-2.0"));
        project.AddLinkLib(_T("gdk-x11-2.0"));
        project.AddLinkLib(_T("atk-1.0"));
        project.AddLinkLib(_T("gdk_pixbuf-2.0"));
        project.AddLinkLib(_T("m"));
        project.AddLinkLib(_T("pangocairo-1.0"));
        project.AddLinkLib(_T("pango-1.0"));
        project.AddLinkLib(_T("cairo"));
        project.AddLinkLib(_T("gobject-2.0"));
        project.AddLinkLib(_T("gmodule-2.0"));
        project.AddLinkLib(_T("dl"));
        project.AddLinkLib(_T("glib-2.0"));
    }

    // enable compiler warnings (project-wide)
    WarningsOn(project, Wizard.GetCompilerID());

    // Debug
    local target = project.GetBuildTarget(Wizard.GetDebugName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
        target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        target.SetWorkingDir(GtkPath + _T("/bin"));
        // enable generation of debugging symbols for target
        DebugSymbolsOn(target, Wizard.GetCompilerID());
    }

    // Release
    target = project.GetBuildTarget(Wizard.GetReleaseName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttExecutable); // ttExecutable: no console
        target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        target.SetWorkingDir(GtkPath + _T("/bin"));
        // enable optimizations for target
        OptimizationsOn(target, Wizard.GetCompilerID());
    }

    return true;
}

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: GTK+ template
« Reply #9 on: November 12, 2006, 02:45:40 pm »
Sorry, it was not the good file :( [...]
Ok - seen this and thanks a lot.
Unfortunately I kind of disagree with some changes:
1.) You basically link against all libs that are in the SDK. This is not required at all and is not a good way to start. I wonder why you've added e.g. all the additional libs to the MS Windows platform - the application compiled and linked just fine before. Maybe I'm missing something here, but why do you do that?
2.) Another issue I found is that you add "-mno-cygwin" on MS windows. This is only required if you use Cygwin which is not natively supported by C::B (although it works). I would prefer not using this switch to avoid incompatibilities and confusions.
I am going to incorporate your deliveries anyway (removing what I think is not necessary) but would welcome comments on that. In addition: If you want to do me a favor, you could tell me the minimum set of libraries required on Linux.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

gege2061

  • Guest
Re: GTK+ template
« Reply #10 on: November 12, 2006, 04:04:29 pm »
1.) You basically link against all libs that are in the SDK. This is not required at all and is not a good way to start. I wonder why you've added e.g. all the additional libs to the MS Windows platform - the application compiled and linked just fine before. Maybe I'm missing something here, but why do you do that?
Is that enough to compile the small example but for greater applications the other libraries can be necessary (it east can be possible to give the choice to the user during the creation of the project?)

2.) Another issue I found is that you add "-mno-cygwin" on MS windows. This is only required if you use Cygwin which is not natively supported by C::B (although it works). I would prefer not using this switch to avoid incompatibilities and confusions.
I use mingw but that seems useless.

In addition: If you want to do me a favor, you could tell me the minimum set of libraries required on Linux.
Yes, I will look at that this evening ;)

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: GTK+ template
« Reply #11 on: November 12, 2006, 04:44:26 pm »
Is that enough to compile the small example but for greater applications the other libraries can be necessary [...]
That's exactly what I mean. They *can*, but don't need to be necessarily. I know, there is this top-bottom approach "just include all it'll always work". But I'm more into the bottom-top "Include only what's required". The reason for this is that you have to think about during development. This will lead automatically into a lot more knowledge and trust in your application in the end. It is *good* to know the dependencies of the applications you are developing in detail. And in the end it is as simple as that:
1.) Look at the linker errors for symbols not resolved
2.) look at the libs for the symbols they export (e.g. using the symbol table plugin)
3.) Add the libs to your project.
I know that there are a lot people out that believe like you do but still: I prefer the minimal set of libs and just hope you understand.
With regards, Morten.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

gege2061

  • Guest
Re: GTK+ template
« Reply #12 on: November 23, 2006, 02:27:14 pm »
In addition: If you want to do me a favor, you could tell me the minimum set of libraries required on Linux.
Code
project.AddLinkLib(_T("gtk-x11-2.0"));
:roll:

The complete file :
Code
////////////////////////////////////////////////////////////////////////////////
//
// GTK project wizard
//
////////////////////////////////////////////////////////////////////////////////

// globals
GtkPathDefault    <- _T("$(#gtk)");
GtkPathDefaultInc <- _T("$(#gtk.include)");
GtkPathDefaultLib <- _T("$(#gtk.lib)");
GtkPath <- _T("");

function BeginWizard()
{
    local intro_msg = _T("Welcome to the new GTK project wizard!\n" +
                         "This wizard will guide you to create a new GTK project\n" +
                         "using the GTK cross-platform GUI toolkit\n\n" +
                         "When you're ready to proceed, please click \"Next\"...");

    local gtkpath_msg = _T("Please select the location of GTK on your computer.\n" +
                           "This is the top-level folder where GTK was installed.\n" +
                           "To help you, this folder must contain the subfolders\n" +
                           "\"include\" and \"lib\".");

    Wizard.AddInfoPage(_T("GtkIntro"), intro_msg);
    Wizard.AddProjectPathPage();
    Wizard.AddGenericSelectPathPage(_T("GtkPath"), gtkpath_msg, _T("GTK's location:"), GtkPathDefault);
    Wizard.AddCompilerPage(_T(""), _T("gcc*"), true, true);
}

////////////////////////////////////////////////////////////////////////////////
// Gtk's path page
////////////////////////////////////////////////////////////////////////////////

function OnLeave_GtkPath(fwd)
{
    if (fwd)
    {
        local dir         = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
        local dir_nomacro = VerifyDirectory(dir);

        if (dir_nomacro.IsEmpty())
            return false;

        // verify include dependencies
        local dir_nomacro_inc = GetCompilerIncludeDir(dir, GtkPathDefault, GtkPathDefaultInc);
        if (dir_nomacro_inc.IsEmpty())
            return false;
        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))
            return false;

        // verify library dependencies
        local dir_nomacro_lib = GetCompilerLibDir(dir, GtkPathDefault, GtkPathDefaultLib);
        if (dir_nomacro_lib.IsEmpty())
            return false;
        if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-2.0"), _T("GTK's")))
            return false;


        GtkPath = dir; // Remember the original selection.

        local is_macro = _T("");

        // try to resolve the include directory as macro
        is_macro = GetCompilerIncludeMacro(dir, GtkPathDefault, GtkPathDefaultInc);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real inc path we had computed instead
            GtkPathDefaultInc = dir_nomacro_inc;
        }

        // try to resolve the library directory as macro
        is_macro = GetCompilerLibMacro(dir, GtkPathDefault, GtkPathDefaultLib);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real lib path we had computed instead
            GtkPathDefaultLib = dir_nomacro_lib;
        }
    }
    return true;
}

// return the files this project contains
function GetFilesDir()
{
    return _T("gtk/files");
}

// setup the already created project
function SetupProject(project)
{
    project.AddIncludeDir(GtkPathDefaultInc);
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("cairo"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0"));
    // Notice GtkPathDefault*Lib* at some positions. This is correct as of 2.8.20
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("pango-1.0"));
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0")  + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));
   

    project.AddLibDir(GtkPathDefaultLib);
    if (PLATFORM == PLATFORM_MSW)
    {
        // add link libraries
        project.AddLinkLib(_T("gtk-win32-2.0"));
        project.AddLinkLib(_T("gobject-2.0"));
        project.AddLinkLib(_T("glib-2.0"));

        // Notice: there are more libs required as the app gets more complex, e.g.:
        // pangocairo-1.0.lib, pangocairo-1.0.lib, libatk-1.0.dll.a,
        // gdk_pixbuf-2.0.lib, gdk-win32-2.0.lib,  pango-1.0.lib,
        // gmodule-2.0.lib,    gthread-2.0.lib,    cairo.lib,
        // pangoft2-1.0.lib    (...)
    }
    else
    {
        project.AddLinkLib(_T("gtk-x11-2.0"));
    }


    // enable compiler warnings (project-wide)
    WarningsOn(project, Wizard.GetCompilerID());

    project.AddCompilerOption(_T("-mms-bitfields"));

    // Debug
    local target = project.GetBuildTarget(Wizard.GetDebugName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
        target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        // enable generation of debugging symbols for target
        DebugSymbolsOn(target, Wizard.GetCompilerID());
    }

    // Release
    target = project.GetBuildTarget(Wizard.GetReleaseName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttExecutable); // ttExecutable: no console
        target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        // enable optimizations for target
        OptimizationsOn(target, Wizard.GetCompilerID());
    }

    return true;
}

;)

gege2061

  • Guest
Re: GTK+ template
« Reply #13 on: November 06, 2007, 10:57:18 pm »
Hello,

I make up this topic, I corrected a problem in the path verification on Linux. Can you activate GTK+ project for Linux ?

Code
////////////////////////////////////////////////////////////////////////////////
//
// GTK project wizard
//
////////////////////////////////////////////////////////////////////////////////

// globals
GtkPathDefault    <- _T("$(#gtk)");
GtkPathDefaultInc <- _T("$(#gtk.include)");
GtkPathDefaultLib <- _T("$(#gtk.lib)");
GtkPath <- _T("");

function BeginWizard()
{
    local intro_msg = _T("Welcome to the new GTK project wizard!\n" +
                         "This wizard will guide you to create a new GTK project\n" +
                         "using the GTK cross-platform GUI toolkit\n\n" +
                         "When you're ready to proceed, please click \"Next\"...");

    local gtkpath_msg = _T("Please select the location of GTK on your computer.\n" +
                           "This is the top-level folder where GTK was installed.\n" +
                           "To help you, this folder must contain the subfolders\n" +
                           "\"include\" and \"lib\".");

    Wizard.AddInfoPage(_T("GtkIntro"), intro_msg);
    Wizard.AddProjectPathPage();
    Wizard.AddGenericSelectPathPage(_T("GtkPath"), gtkpath_msg, _T("GTK's location:"), GtkPathDefault);
    Wizard.AddCompilerPage(_T(""), _T("gcc*"), true, true);
}

////////////////////////////////////////////////////////////////////////////////
// Gtk's path page
////////////////////////////////////////////////////////////////////////////////

function OnLeave_GtkPath(fwd)
{
    if (fwd)
    {
        local dir         = Wizard.GetTextControlValue(_T("txtFolder")); // txtFolder is the text control in GenericSelectPathPage
        local dir_nomacro = VerifyDirectory(dir);

        if (dir_nomacro.IsEmpty())
            return false;

        // verify include dependencies
        local dir_nomacro_inc = GetCompilerIncludeDir(dir, GtkPathDefault, GtkPathDefaultInc);
        if (dir_nomacro_inc.IsEmpty())
            return false;
        if (!VerifyFile(dir_nomacro_inc + wxFILE_SEP_PATH + _T("gtk-2.0") + wxFILE_SEP_PATH +_T("gtk"), _T("gtk.h"), _T("GTK's include")))
            return false;

        // verify library dependencies
        local dir_nomacro_lib = GetCompilerLibDir(dir, GtkPathDefault, GtkPathDefaultLib);
        if (dir_nomacro_lib.IsEmpty())
            return false;
        if (PLATFORM == PLATFORM_MSW)
        {
            if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-win32-2.0"), _T("GTK's")))
                return false;
        }
        else
        {
            if (!VerifyLibFile(dir_nomacro_lib, _T("gtk-x11-2.0"), _T("GTK's")))
                return false;
        }

        GtkPath = dir; // Remember the original selection.

        local is_macro = _T("");

        // try to resolve the include directory as macro
        is_macro = GetCompilerIncludeMacro(dir, GtkPathDefault, GtkPathDefaultInc);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real inc path we had computed instead
            GtkPathDefaultInc = dir_nomacro_inc;
        }

        // try to resolve the library directory as macro
        is_macro = GetCompilerLibMacro(dir, GtkPathDefault, GtkPathDefaultLib);
        if (is_macro.IsEmpty())
        {
            // not possible -> use the real lib path we had computed instead
            GtkPathDefaultLib = dir_nomacro_lib;
        }
    }
    return true;
}

// return the files this project contains
function GetFilesDir()
{
    return _T("gtk/files");
}

// setup the already created project
function SetupProject(project)
{
    project.AddIncludeDir(GtkPathDefaultInc);
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gtk-2.0"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("cairo"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("gdk"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("glib-2.0"));
    // Notice GtkPathDefault*Lib* at some positions. This is correct as of 2.8.20
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("glib-2.0") + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("pango-1.0"));
    project.AddIncludeDir(GtkPathDefaultLib + wxFILE_SEP_PATH + _T("gtk-2.0")  + wxFILE_SEP_PATH + _T("include"));
    project.AddIncludeDir(GtkPathDefaultInc + wxFILE_SEP_PATH + _T("atk-1.0"));
   

    project.AddLibDir(GtkPathDefaultLib);

    if (PLATFORM == PLATFORM_MSW)
    {
      // add link libraries
      project.AddLinkLib(_T("gtk-win32-2.0"));
      project.AddLinkLib(_T("gobject-2.0"));
      project.AddLinkLib(_T("glib-2.0"));

      // Notice: there are more libs required as the app gets more complex, e.g.:
      // pangocairo-1.0.lib, pangocairo-1.0.lib, libatk-1.0.dll.a,
      // gdk_pixbuf-2.0.lib, gdk-win32-2.0.lib,  pango-1.0.lib,
      // gmodule-2.0.lib,    gthread-2.0.lib,    cairo.lib,
      // pangoft2-1.0.lib    (...)
    }
    else
    {
        project.AddLinkLib(_T("gtk-x11-2.0"));
    }

    // enable compiler warnings (project-wide)
    WarningsOn(project, Wizard.GetCompilerID());

    project.AddCompilerOption(_T("-mms-bitfields"));

    // Debug
    local target = project.GetBuildTarget(Wizard.GetDebugName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttConsoleOnly); // ttConsoleOnly: console for debugging
        target.SetOutputFilename(Wizard.GetDebugOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        // enable generation of debugging symbols for target
        DebugSymbolsOn(target, Wizard.GetCompilerID());
    }

    // Release
    target = project.GetBuildTarget(Wizard.GetReleaseName());
    if (!IsNull(target))
    {
        target.SetTargetType(ttExecutable); // ttExecutable: no console
        target.SetOutputFilename(Wizard.GetReleaseOutputDir() + Wizard.GetProjectName() + DOT_EXT_EXECUTABLE);
        // enable optimizations for target
        OptimizationsOn(target, Wizard.GetCompilerID());
    }

    return true;
}