Wednesday, March 23, 2011

Compiling GTKGlExt in Windows using MinGW

I spent two weeks of free time trying to figure out how to compile GTKGlExt in Windows.  It's no easy task. GTKGlExt is old.  It hasn't been updated in a long time, from what I can tell.  It's instructions are even older - there are some new issues that the instructions do not adress.

First of all - I had a lot better luck using MinGW through MSYS than I did with cygwin.  Cygwin tends to chock on windows \r characters, which seem to crop up through the pkg-config utility and then spread like a sick disease.  There also may be conflicts between it and the MinGW toolchain. You can read about some of these issues here.

The general gist of things is that you should install MinGW with MSYS, then follow the instructions in the GTKGlExt zip file, but you need to remove some references to pangox.  More complete instructions follow:

1) Download MinGW. It can be had from http://www.mingw.org/.  When you start installing it, be sure to check the box for MSYS.   Also, I recommend installing it to the default location - C:/MinGW/

2) Install GTK+.  I personally use the bundle, available from http://www.gtk.org/download-windows.html  I download the All-in-one bundle, version 2.22.  I unzip the contents to C:/gtk+bundle/  Do NOT use a directory with spaces in it, as this will screw up the pkg-config utility.

3) Download GTKGlExt.  I specifically downloaded the 1.2.0 Release from 2006. Open up the archive, if you do not have a program that will handle this file, 7-Zip is free and it should work.  I recommend decompressing the files to C:/gtkglext/ .  The docs folder should then be C:/gtkglext/docs. It should NOT be C:/gtkglext/gtkglext-1.2.0/docs. Do NOT use a directory with spaces in it, as this will screw up the pkg-config utility.

4) Open C:/gtkglext/configure in a text editor. And remove all references to pangox.
Delete lines like these:
pangox >= 1.0.0 \\
And remove the pangox from inside this line:
GDKGLEXT_PACKAGES="gdk-2.0 pango pangox gmodule-2.0"
This step may break compatibility with linux, but, you should probably have a separate copy for that anyway.  Maybe someone out there who is more experienced than I can fix this issue so we don't have to do this? You can read more about that here.

5) Various files have old deprecated macros in them.  These replacement functions were found in the GtkWidget documentation page in the GTK+ Reference Manual


Macro GTK_WIDGET_REALISED needs to be replaced with function gtk_widget_get_realized. The parameters are the same.  Do this at:
- c:\gtkglext\gtk\gtkglwidget.c - lines 130, 157, 177, 197, 254, 435, 477, 504

Macro GTK_WIDGET_TOPLEVEL needs to be replaced with function gtk_widget_is_toplevel . The parameters are the same.  Do this at:

 - c:\gtkglext\gtk\gtkglwidget.c - line 177

Macro GTK_WIDGET_NO_WINDOW  needs to be replaced with function !gtk_widget_get_has_window. The parameters are the same.  Note the logical "NOT" operator, the new function has the opposite behavior as the old macro. Do this at:
- c:\gtkglext\gtk\gtkglwidget.c - line 253 - Note that adding a NOT operator to this line would yield, 2 NOTs, so you can just remove the existing NOT instead of adding one.

7) Open up MinGW Shell from the Start menu.  This will give you a linux-like bash shell for you to enter commands.  It is very helpful to understand how to use bash when doing these sorts of things.

Some things to note:
  • To get to your C: drive you would go to the directory /c/ by entering:
    cd /c/
  • Symbolic links don't exist in MSYS. If you try to make one, it actually makes a copy of the directory.  This can lead to confusion later.
8) The following instructions are adapted from the README.win32 file included with the GTKGlExt package.  Enter these commands into the MinGW shell prompt:
cd /c/gtkglext
export PATH=/c/gtk+bundle/bin:$PATH
export PKG_CONFIG_PATH="c:/gtk+bundle/lib/pkgconfig"
export PATH=/c/MinGW/bin:$PATH
env CC='gcc -march=pentium' \
          ./configure --prefix=c:/gtkglext \
          --build=i386-pc-mingw32 \
          --disable-static
make
make install
Just as a note, if you do as recommended in the README.win32 file and enable the --enable-debug=yes option, this will create errors.  I have a post about this here.

 At this point you should have the libraries and DLLs built.  The next logical step is to build the examples.

9) This step is needed because pkg-config likes to leave carriage return characters in its output. Open up the file c:/gtkglext/examples/Makefile.mingw and pipe the pkg-config output through the command  tr -d "\r" in lines 9 through 11.  They should look like this (I apologize that blogger is wrapping the lines, disregard that):

before:
INCLUDES := $(shell pkg-config --cflags gtkglext-1.0 pangoft2)
LIBS := $(shell pkg-config --libs gtkglext-1.0)
LIBS_WITH_PANGOFT2 := $(shell pkg-config --libs gtkglext-1.0 pangoft2)
after:

INCLUDES := $(shell pkg-config --cflags gtkglext-1.0 pangoft2 | tr -d "\r")
LIBS := $(shell pkg-config --libs gtkglext-1.0 | tr -d "\r")
LIBS_WITH_PANGOFT2 := $(shell pkg-config --libs gtkglext-1.0 pangoft2 | tr -d "\r")
10) Now at the MSYS prompt, type the following lines (be sure that you have have the previous PATH and PKG_CONFIG_PATH commands from before):
$ cd /c/gtkglext/examples
$ make -f Makefile.mingw
11) Run an example program, my favorite is shapes.exe:
$ shapes.exe
At this point you have a running program.   If you close MSYS and you want to run the programs in the future, you will need the DLLs.  One simple way to do this is to copy the exe file you want to run to a new folder, and copy the DLLs from c:/gtk+bundle/bin and c:/gtkglext/bin into the same folder with the exe.  At that point you can run it any time you want.

I plan to follow up soon with an explanation of how to setup a project in Eclipse that includes everything you need to use GTKGlExt.  At that point you can easily experiment with some code of your own! Check back later!

STMicro's STMPE16M31 - A classic example of cumbersome power supply and signal level design.

STMicro's STMPE16M31 is a touch sensor IC that is designed to operate from one external power supply between 2.7 and 5.5V.  Great, right?  Well the dirty little secret on this thing is that its interface signals are scaled at 1.8V. 

Why not buffer these signals internally to match the input supply voltage of 2.7 to 5.5V?  That would make a lot more sense to me, considering I have this supply voltage available, which means I probably use it as a signal level.  Instead, they assume I have 1.8V signaling capabilities available.  If I had that, then I would probably have a 1.8V voltage supply I could power the device from - and it would be significantly more efficient than their internal regulator.  Also, the rail inside the IC is probably at a different voltage than the 1.8V level I use outside the device, which means my signal level will be slightly different as well - probably not an issue looking at the spec sheet, but it doesn't make me feel any better about the design.

The part seems to work great, but I hate the complexity of making a design around it.

Tuesday, March 22, 2011

A GTKGlExt Compile Issue: error: dereferencing pointer to incomplete type

If you see this while running make on GTKGlExt:
gdkglwindow.c: In function 'gdk_window_set_gl_capability':
gdkglwindow.c:743:3: error: dereferencing pointer to incomplete type
gdkglwindow.c:749:3: error: dereferencing pointer to incomplete type
it might be because you ran configure with the  "--enable-debug=yes" option.  If this option is absent, it will use the default minimum setting, which is safer than the no setting.  Doing this will change some defines related to depreciation that appear to be killing the build at this point - I am guessing this issue emerged as GTK changed since GTKGlExt was released in 2006.

To fix it, run the ./configure command as before without the --enable-debug option, then try make again.  I hope that works for you.

Maybe someone out there can get the root cause of this fixed one day? *hint hint*

Monday, March 21, 2011

Microsoft Excel: Yet another bug.

I tried importing a terribly formatted LTSpice output file into Excel today, only to find that when you use fixed column widths, using their handy little tool that lets you put verticle lines between text - that those lines don't actually mean anything.  As you scroll left and right in the view, the lines jump around left to right, and end up somewhere you don't want them.



How long has Microsoft been making Excel? It still has stupid problems like these, in simple features? And you want me to buy a new version, when you can't even get the old version right?  I can only imagine what bugs were added when they switched to that awful new user interface.

Side note: it looks like LibreOffice seems to work.  Progress continues...

Saturday, March 12, 2011

GtkGLExt - No love for windows.

I have this running theory: if open source were easy, every one would use it.  I try and use this blog to help with this, and complain when I can't.

This is a work in progress acting as my scratchpad while I work through the issues.  I plan to clean this post up once I am finished.

I am trying to get GtkGLExt working in windows.  Definately not something you would want to do if you don't have experience linux / bash / shell scripting / configure scripts / etc.

First, it seems pretty mandatory that you install cygwin. Also note, by default, it will not put in all the packages you need.  You are going to need to install some extras.  For instance, you will need the package with "ar" in it.

Then you are going to need to figure out how to get to your various places in the file system.  Hint: the "/cygdrive/"  fake directory takes you to the root of your file system, so "C:/" is at "/cygdrive/c/"

Second, straight out of the box gcc (MinGW) is going to crash.  You must run export TEMP="/tmp/" to get the crash to go away.  What a weird crash - no error message or anything.

Then you are going to need to address this problem:
http://mail.gnome.org/archives/gtkglext-list/2006-November/msg00003.html
I dealt with it by removing all references to pangox in the configure file.

Then I came upon this problem, elaborated in config.log:
configure:20297: gcc -march=pentium -o conftest.exe -g -O2 -Wall -g -mms-bitfields -mms-bitfields -IC:/gtk+bundle/include/glib-2.0 -IC:/gtk+bundle/lib/glib-2.0/include 

   conftest.c  -LC:/gtk+bundle/lib -lglib-2.0 -lintl 

 >&5
gcc.exe: : Invalid argument
gcc.exe: : Invalid argument
This problem is due to some '\r' characters getting picked up in the C include paths and the libs path (I presume they come from pkg-config running in windows).  I had to strip them - more on that whenever I update this page.

Sometimes on multiple attempts at make I get this:
.deps/gdkglenumtypes.Plo:1: *** multiple target patterns.  Stop.
The solution to that is to overwrite the relevant .deps folder with the on out of the original zip file.  These files contain dummy text that will then get overwritten again by make.  I am not sure why this occurs in the first place.


Another problem I got was this:
/bin/sh: line 1: glib-mkenums: command not found
This is a perl script that needs to be run. It comes with GTK+.  I am using the GTK+ All-in-one bundle for Windows, installed at C:/gtk+bundle so I needed to include C:/gtk+bundle/bin in my PATH.  You might also get this if you don't have the perl package installed in your cygwin?