Author Topic: multiplatform GTK proyect  (Read 17889 times)

epsilon_da

  • Guest
multiplatform GTK proyect
« on: April 08, 2009, 06:17:15 pm »
Hi.

I use codeblocks to program GTK applications together with some other libs like libusb and fftw3.

I programm mainly on linux i note lots of diferences which i will list on this post.

On OpenSuse,  Codeblocks 8.02 Build Mar 12 2009 svn 5483
On Windows,   Codeblocks 8.02 Build Feb 27 2008 no svn info

I started the first time with the GTK template, which in my opinion is incomplete.
It creates a simple, empty, non-portable Proyect with some gtk lines.

   GTK uses pkg-config for mostly everything.
   There are other ..-config programs like libusb-config
   Thoose programs makes life easier. And and can list "some" available libs on the libraries tab.

   On windows, the template AND the user have to add each include and linker related directory, which for GTK, are a lot. So it makes lernning GTK with codeblocks much more difficult for beginners.
   The options created by the template are global for the proyect and are not platform independent, so to compile the same proyect on linux, one have to re-estructure entirely the proyect and mantain a Debug/Release target for each OS. Debug-Win32, Debug-Linux, Release-Win32, Release-Linux,...
   This wont be necessary if pkg-config output where supported on windows too.
   It would be easier if the "libraries" tab worked in the same way for both platforms with all ..-config tools. Of course, a dialog to set the path to thoose tools will need to be available.


The Linux version have a funny limitation. The Linux version of CB can not edit the build properties of a target selected for windows, but the windows version can edit the properties for linux. I dont understand this limitation.

There should be also 2 versions of windows available. The "real" windows and CrossCompiling with MinGW for windows on linux. That is, producing exe's on linux.

That will make easier to use Codeblocks, and produce multiplatform opensource software.

Outside of that, Codeblocks is the best IDE ever.
I dont know why isnt it more used instead of Anjuta or KDevelop.



Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #1 on: April 08, 2009, 06:41:50 pm »
patches very welcome :)

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #2 on: April 08, 2009, 07:16:07 pm »
I see, a bugreport isnt acepted without a patch to fix it.
Sure, then we will wait a couple of years with lucky, until i get used to wxwidgets and the codeblocks source code, and some have some other things in life finished. And, of course, it may not be acepted in main stream. At the end, it is easier to live with both problems. :)

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #3 on: April 08, 2009, 07:53:07 pm »
I wasn't trying to be a wise guy with my response. I suggested a patch because:

* you gave us a detailed report suggesting you know enough about GTK to make a useful contribution;
* the wizards are scripted and should be relatively easy to understand for a newcomer;
* open source is all about scratching your own itch -- I don't know if any of the devs are using GTK as extensively as you are (I use pygtk from time to time, which is clearly irrelevant)
* we're actually pretty good about accepting patches. we have the usual open source problem of not enough hands to handle all of the requests.

If you don't want to contribute patches, it would be most helpful if you submit issues to the bug tracker or as a feature request. e.g. report bugs at http://developer.berlios.de/bugs/?group_id=5358

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #4 on: April 08, 2009, 08:03:06 pm »
   It would be easier if the "libraries" tab worked in the same way for both platforms with all ..-config tools. Of course, a dialog to set the path to thoose tools will need to be available.

that can be done in the wizard scripts.
alternatively, you have the wizard create global variables to allow the user to set paths to executables via that panel (this tends to be more useful on windows than on linux systems)

for more info:

http://wiki.codeblocks.org/index.php?title=Wizard_scripts

Quote
There should be also 2 versions of windows available. The "real" windows and CrossCompiling with MinGW for windows on linux. That is, producing exe's on linux.

you should be able to do that by creating a new compiler and setting up the appropriate tool chain.
« Last Edit: April 08, 2009, 08:08:58 pm by dmoore »

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #5 on: April 09, 2009, 04:45:28 am »
ok. I will check that about wizard scripts and try to make a portable GTK template.

But i think that the problem wont be fixed by that.

At the gtk wizard.script is this:

Code
if (PLATFORM == PLATFORM_MSW)
    {
        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    (...)

        project.AddCompilerOption(_T("-mms-bitfields"));
    }
    else
    {
        /*if (GtkVersion == 1)
        {*/
        project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags`"));
        project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs`"));
        /*}
        else
        {
            project.AddCompilerOption(_T("`pkg-config gtk+ --cflags`"));
            project.AddLinkerOption(_T("`pkg-config gtk+ --libs`"));
        }*/
    }


If you have programmed on linux you can see the special quotes used with pkg-config.
Thoose are not supported by windows so it wont work with a just system() or exec() call.
I have attached some screenshots to be more clear.

One shows my project setup, focused on the windows target and everything disabled. It shouldnt be. I should be able to change my own project options.
It also shows the pkg-config and others "--cflags" in an offtopic(?) place "Other options". Thoose lines should be somehow under the search Tab and be autoconfigured acordingly to the selected "Libraries used in the project" as shown in the other sshot.
This Libraries dialog should also be part of each target configuration, and not globals per project.
Windows may require sometimes different libs. Like if you use, libusb on linux and the windows USB-API. There are also differences on some export simbols used by glade to autoconnect signals.

The last images, shows error messages because the pkg-config call is not being executed, and the include and linker dirs are not found.

One can know where is pkg-config on windows. If you setup the GTK path then it is at $GTK/bin/pkg-config.exe
Then codeblocks should do what windows doesnt on parsing the special quotes `...`


What i am trying to say is that, i can make different targets for each OS an have a different configuration for each one, but this may be a work around to the better fix.
If the toolkit used is platform independent, ¿shouldnt it by default be configured the same on all platforms?

Also, it seems strange to configure a project on linux and CB, because all the normal lines are always on places like "Other Options" or "Other linker options" or "Other stuff", thoose places are always like "almost never used" or "use with acknowledge", and are not very obvius to the beginner.


I will post here my GTK template when i have it working because here is more handy to me.


[attachment deleted by admin]

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #6 on: April 09, 2009, 05:09:36 am »
Then codeblocks should do what windows doesnt on parsing the special quotes `...`

IIRC, codeblocks provides support for backticks in build settings on windows (try it)

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #7 on: April 09, 2009, 10:09:45 am »
hehe, i tried, of course, you can see the screenshots and it doesnt works.
Not with pkg-config alone, and not with the full path.
Can you show me an example?

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #8 on: April 09, 2009, 03:54:18 pm »
works for me

goto project -> build options -> compiler settings -> other options add the text

Code
`c:\gtk\bin\pkg-config gtk+-2.0 --cflags --errors-to-stdout`

You can see the compiler command lines and output after switching on full compiler logging in the compiler settings. In my case I get an error because PKG_CONFIG_PATH wasn't set

btw folks, it is a little worrying that if the back tick fails to execute C::B proceeds as if nothing is wrong. e.g. if pkg-config is missing wouldn't it be better to produce a compiler error, or at least a warning (maybe I've missed something)

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #9 on: April 09, 2009, 06:42:56 pm »
 :shock:

ok. it worked.
I couldnt see the output, i just cant find an option to enable all outputs which works. Only all warnnings (-Wall)
I also couldnt find the pkg_config_path variable, but as it worked, i supose that it is correctly set.

thanks.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #10 on: April 09, 2009, 07:57:27 pm »
I couldnt see the output, i just cant find an option to enable all outputs which works.

settings -> compiler and debugger -> global compiler settings -> other settings -> compiler logging

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #11 on: April 09, 2009, 10:05:21 pm »
Thanks.

I have 2 questions about the scripting.

It seems like a will have to create different targets (i dont know how yet) for each OS unless CB supports the next stuff:

To be able to use the same pkg-config commands on any os, then it muss be on the path.
project.AddCompilerOption(_T("`pkg-config gtk+-2.0 --cflags --errors-to-stdout`"));
project.AddLinkerOption(_T("`pkg-config gtk+-2.0 --libs --errors-to-stdout`"));

I need that codeblocks adds   GtkPathDefaultBin   to the path only when the project is run in windows. For that i need an script to be executed before each compilation and be able to check this variables and save it to the PATH before running gcc or the backquoted code.
Can this be done in "PRE build steps"?
Where is a tutorial or documentation or code examples to know what kind of scripting is used on this place.

Also i have to add -mms-bitfields to gcc only on windows

if _os_ == Windows:
   PATH += GtkPathDefault + FILE_SEP_PATH + "bin"
   CC += CC + "-mms-bitfields"

(Assuming that PATH and CC is reseted on every run)

OR -mms-bitfields, could be added directly to "Compiler Flags".
Also   -mno-cygwin  is an useful flag too.
Both should only be when compiling on windows.


Quote
If the API uses structs with certain kinds of bitfields, you must use the flag -mms-bitfields in gcc for the struct field packing to be identical to that MSVC uses. GTK+ uses such API, and the commonly used GTK+ binaries built by TorLillqvist are compiled using gcc with this flag. They are thus also usable from MSVC code, and when building GTK+-using software with gcc, the flag must also be used.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #12 on: April 09, 2009, 10:42:06 pm »
take a look at the wxWidgets wizard script as it uses the PLATFORM constant to determine which OS (see here for more on Scripting http://wiki.codeblocks.org/index.php?title=Scripting_commands).

I don't think there is support for setting the path via a script (yet). An alternative to setting the path is to define a custom variable for the project in project -> build options -> custom variables, say

gtk_bin_dir = C:\GTK\bin\

on win32 and leave it empty on linux. then your back tick would be:

`$(gtk_bin_dir)pkg-config gtk+-2.0 --cflags`

to do that in a script I think you would use the SetVar method of CompilerOptionsBase

epsilon_da

  • Guest
Re: multiplatform GTK proyect
« Reply #13 on: April 09, 2009, 11:04:51 pm »
But i am on the same problem here, or not?

IF i have gtk_bin_dir setted to some path on windows side and then try to compile con linux, the path will be wrong.
I need to update this variable every time the program is built and check for OS.

I am currently reading what you gave me. Thanks.


Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: multiplatform GTK proyect
« Reply #14 on: April 09, 2009, 11:15:34 pm »
IF i have gtk_bin_dir setted to some path on windows side and then try to compile con linux, the path will be wrong.
I need to update this variable every time the program is built and check for OS.

you could have the wizard add a build script to check platform and define variables accordingly every build.
Not sure how you will deal with cross-compiling...