cross posted from forum.peoplecards.ca on behalf of mfisher_ixFor kicks I wanted to try running Brian’s OpenCOBOL GTK+ demo, which consists of ocgtk.c and gtkhello.cob:
http://opencobol.add1tocobol.com/sources/ocgtk.chttp://opencobol.add1tocobol.com/sources/gtkhello.cobA few errors can occur when compiling. For reference I wanted to list them all here, along with how to resolve them. But first of all I should describe my MinGW, OpenCOBOL, and GTK+ installations.
My OpenCOBOL 1.1. installation was built from source code in 64-bit Windows 7, using MinGW. My MinGW/MSYS installation was installed using the MinGW command line interface installer, version mingw-get-0.4-mingw32-alpha-1. Post-installation setup was done using /post-install/pi.sh.
In building OpenCOBOL 1.1, I generally followed Gary Cutler’s “Build Guide”, except that I used the latest available versions of PDCurses and GMP, and replaced Berkeley DB with VBISAM 2.0.
My GTK+ installation consisted of extracting the latest all-in-one bundle for 32-bit Windows to /mingw/opt/gtk (i.e., C:\MinGW\msys\opt\gtk). I also created a file named .profile in my MSYS home directory, containing the following line:
export PATH=$PATH:/opt/gtk/bin
Ordinarily your .profile file will get "sourced" into a new MSYS session, and will set your environment accordingly. To source it into your current MSYS session, use the shell's dot command:
A simple-minded attempt at compiling ocgtk.c to an object module yields the expected error regarding gtk/gtk.h:
$ gcc -c ocgtk.c
ocgtk.c:8:21: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
A more sophisticated attempt yields errors regarding cob_module:
$ gcc -c `pkg-config --cflags --libs gtk+-2.0` ocgtk.c
ocgtk.c: In function ‘CBL_OC_GTK_WINDOW_SET_TITLE’:
ocgtk.c:30:5: error: unknown type name ‘cob_module’
ocgtk.c:34:12: warning: assignment from incompatible pointer type [enabled by default]
ocgtk.c:35:25: error: request for member ‘cob_procedure_parameters’ in something not a structure or union
ocgtk.c: In function ‘CBL_OC_GTK_ENTRY_GET_TEXT’:
ocgtk.c:107:5: error: unknown type name ‘cob_module’
ocgtk.c:111:12: warning: assignment from incompatible pointer type [enabled by default]
ocgtk.c:112:24: error: request for member ‘cob_procedure_parameters’ in something not a structure or union
Edit ocgtk.c, and replace both occurrences of:
with:
struct cob_module *module;
Try compiling ocgtk.c again:
$ gcc -c `pkg-config --cflags --libs gtk+-2.0` ocgtk.c
This succeeds, and causes ocgtk.o to be generated. Now try compiling gtkhello.cob and linking it with ocgtk.o:
$ cobc -x gtkhello.cob ocgtk.o
ocgtk.o:ocgtk.c:(.text+0x2e): undefined reference to `gtk_init_check_abi_check’
ocgtk.o:ocgtk.c:(.text+0×57): undefined reference to `gtk_window_new’
ocgtk.o:ocgtk.c:(.text+0xb1): undefined reference to `gtk_window_get_type’
ocgtk.o:ocgtk.c:(.text+0xc0): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0xcf): undefined reference to `gtk_window_set_title’
ocgtk.o:ocgtk.c:(.text+0xed): undefined reference to `gtk_widget_get_type’
ocgtk.o:ocgtk.c:(.text+0xfc): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0×112): undefined reference to `gtk_widget_set_size_request’
ocgtk.o:ocgtk.c:(.text+0×123): undefined reference to `gtk_container_get_type’
ocgtk.o:ocgtk.c:(.text+0×132): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0x13e): undefined reference to `gtk_container_set_border_width’
ocgtk.o:ocgtk.c:(.text+0x15c): undefined reference to `gtk_vbox_new’
ocgtk.o:ocgtk.c:(.text+0×176): undefined reference to `gtk_hbox_new’
ocgtk.o:ocgtk.c:(.text+0×187): undefined reference to `gtk_box_get_type’
ocgtk.o:ocgtk.c:(.text+0×196): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0x1b7): undefined reference to `gtk_box_pack_start’
ocgtk.o:ocgtk.c:(.text+0x1ce): undefined reference to `gtk_button_new_with_label’
ocgtk.o:ocgtk.c:(.text+0x1db): undefined reference to `gtk_entry_new’
ocgtk.o:ocgtk.c:(.text+0x1e8): undefined reference to `gtk_entry_get_type’
ocgtk.o:ocgtk.c:(.text+0x1f7): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0×206): undefined reference to `gtk_entry_set_text’
ocgtk.o:ocgtk.c:(.text+0x22a): undefined reference to `gtk_entry_get_type’
ocgtk.o:ocgtk.c:(.text+0×239): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0×241): undefined reference to `gtk_entry_get_text’
ocgtk.o:ocgtk.c:(.text+0x2d2): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0x2fc): undefined reference to `g_signal_connect_data’
ocgtk.o:ocgtk.c:(.text+0x30d): undefined reference to `gtk_container_get_type’
ocgtk.o:ocgtk.c:(.text+0x31c): undefined reference to `g_type_check_instance_cast’
ocgtk.o:ocgtk.c:(.text+0x32b): undefined reference to `gtk_container_add’
ocgtk.o:ocgtk.c:(.text+0x33e): undefined reference to `gtk_widget_show’
ocgtk.o:ocgtk.c:(.text+0x34b): undefined reference to `gtk_main’
ocgtk.o:ocgtk.c:(.text+0×358): undefined reference to `gtk_main_quit’
collect2: ld returned 1 exit status
Try again, using pkg-config:
$ cobc `pkg-config --cflags --libs gtk+-2.0` -x gtkhello.cob ocgtk.o
C:\MinGW\bin\cobc.exe: unrecognised option `-mms-bitfields’
Have a look at what `pkg-config –cflags –libs gtk+-2.0` has been generating:
$ pkg-config --cflags --libs gtk+-2.0
-mms-bitfields -IC:/MinGW/msys/1.0/opt/gtk/include/gtk-2.0 -IC:/MinGW/msys/1.0/opt/gtk/lib/gtk-2.0/include
-IC:/MinGW/msys/1.0/opt/gtk/include/atk-1.0 -IC:/MinGW/msys/1.0/opt/gtk/include/cairo
-IC:/MinGW/msys/1.0/opt/gtk/include/gdk-pixbuf-2.0 -IC:/MinGW/msys/1.0/opt/gtk/include/pango-1.0
-IC:/MinGW/msys/1.0/opt/gtk/include/glib-2.0 -IC:/MinGW/msys/1.0/opt/gtk/lib/glib-2.0/include
-IC:/MinGW/msys/1.0/opt/gtk/include -IC:/MinGW/msys/1.0/opt/gtk/include/freetype2
-IC:/MinGW/msys/1.0/opt/gtk/include/libpng14 -LC:/MinGW/msys/1.0/opt/gtk/lib -lgtk-win32-2.0
-lgdk-win32-2.0 -latk-1.0 -lgio-2.0 -lpangowin32-1.0 -lgdi32 -lpangocairo-1.0
-lgdk_pixbuf-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lglib-2.0 -lintl
How to eliminate the unrecognized cobc option? Let’s direct the output from pkg-config to a file:
$ echo `pkg-config --cflags --libs gtk+-2.0` > gtk-conf
Edit gtk-conf, and delete “-mms-bitfields”. Try again as follows:
$ cobc `cat gtk-conf` -x gtkhello.cob ocgtk.o
This succeeds, and generates gtkhello.exe. Run it:
You should see Brian’s OpenCOBOL GTK+ demo. (Thanks for the cool code, Brian.)