Jump to content
Excelsior Forums
rms

GTK+ in Modula 2

Recommended Posts

I want to use the GTK+ package with Modula.  I assume that I could write a wrapper for all the calls, compile it, use H2D to create a .DEF file, and import it.  Does this sound reasonable?  Am I missing an important step, or a shortcut?

Also, has anybody else done this?  I don't want to reinvent the wheel.

Thanks

Robert

( PS: the handle is not bizarre Stallman worship; it really is my initials )

Share this post


Link to post
Share on other sites

Looks interesting.  I've just made one quick test, and received an error in gtk2.mod -- but it's late, so I'll have to explore tomorrow.  Looks like nice work, thanks.

Share this post


Link to post
Share on other sites

At the risk of sounding brainless, I have to ask:  Where do I find the Xlib libraries that I need to put in to the lib/ directory?

I've done a locate on the names shown in the project file, and looked in the xds/ and many of my system libraray directories, and I don't see them. 

This is on Linux, if it's significant.

Share this post


Link to post
Share on other sites

At the risk of sounding brainless, I have to ask:  Where do I find the Xlib libraries that I need to put in to the lib/ directory?

I've done a locate on the names shown in the project file, and looked in the xds/ and many of my system libraray directories, and I don't see them. 

This is on Linux, if it's significant.

You've asked right question.

Quote from readme.txt:

"1) Create *.lib file (xlib /implib  <name>.lib <name>.dll)"

It is on Windows.

I've installed GTK+ and run command shown above in folder C:\Program Files\Common Files\Gtk\2.0\bin for each dll found there.

I don't know where *.so libs located on Linux, but I think it is something like /usr/lib or /lib.

Run command "xlib /implib <name>.lib <name>.so" there and you'll get libs you need. Copy them (*.lib) to "lib" folder near with hello.mod, correct *.prj file (lib names should be exact) and compile.

Share this post


Link to post
Share on other sites

Ah, ok, thanks.  I've basically just done a symlink to the latest version of the shared library.

Making progress .. still can't compile Hello but things are moving along.

Share this post


Link to post
Share on other sites

The problem varies.  I must admit that I don't use project files much, so I don't have much familiarity with using them when they are provided by others.

Also, I have made one significant change to your code, I have deleted all references to the win32 library, since I have no such library, and this is on Linux.

using: xc Hello.mod -prj=Hello.prj

I get:

XDS Oberon-2 v2.40 [x86, v1.50] - build 10.05.2005
Compiling "Hello.mod"

* [Hello.mod 10.01 E082]
* expected start of declaration
$FROM SYSTEM IMPORT CAST, ADR, BYTE;

* [Hello.mod 13.29 E081]
* expected start of factor
  String = POINTER TO ARRAY $[0..MAX(INTEGER)-1] OF lg.gchar;

* [Hello.mod 13.44 E008]
* expected symbol  "OF"
  String = POINTER TO ARRAY [0..MAX(INTEGER$)-1] OF lg.gchar;

* [Hello.mod 13.45 E083]
* expected start of type
  String = POINTER TO ARRAY [0..MAX(INTEGER)$-1] OF lg.gchar;

* [Hello.mod 13.46 E082]
* expected start of declaration
  String = POINTER TO ARRAY [0..MAX(INTEGER)-$1] OF lg.gchar;

* [*** 0.00 F437]
* #too many errors
errors  6, no warnings, lines   13, time  0.35

Using: xc -project=Hello.prj Hello.mod

I get:

XDS Modula-2 v2.40 [x86, v1.50] - build 10.05.2005
Compiling "Hello.mod"

* [Hello.mod 28.23 W301]
* parameter "Widget" is never used
PROCEDURE ["C"] hello($Widget: gtk.PGtkWidget; Data: lg.gpointer);

* [Hello.mod 28.47 W301]
* parameter "Data" is never used
PROCEDURE ["C"] hello(Widget: gtk.PGtkWidget; $Data: lg.gpointer);

* [Hello.mod 33.31 W301]
* parameter "Widget" is never used
PROCEDURE ["C"] delete_event( $Widget: gtk.PGtkWidget; Event: gdk.PGdkEv...

* [Hello.mod 33.55 W301]
* parameter "Event" is never used
PROCEDURE ["C"] delete_event( Widget: gtk.PGtkWidget; $Event: gdk.PGdkEv...

* [Hello.mod 33.77 W301]
* parameter "Data" is never used
...dget: gtk.PGtkWidget; Event: gdk.PGdkEvent; $Data: lg.gpointer):lg.gint;

* [Hello.mod 41.25 W301]
* parameter "Widget" is never used
PROCEDURE ["C"] destroy($Widget: gtk.PGtkWidget; Data: lg.gpointer);

* [Hello.mod 41.49 W301]
* parameter "Data" is never used
PROCEDURE ["C"] destroy(Widget: gtk.PGtkWidget; $Data: lg.gpointer);
no errors, warnings  7, lines   79, time  0.31

Share this post


Link to post
Share on other sites

That was one of the things I'd originally tried, before I had all the libraries.  After that, I looked at xc.pdf to see what it said, and tried using a few of the ways it showed it.

Anyway, still erroring out on me :/

xc =p Hello.prj 2>&1 1>& output.txt

http://www.aliboom.com/output.txt

trying to regenerate all the modules:

xc =p =all Hello.prj 2>&1 1>& outputAll.txt

http://www.aliboom.com/outputAll.txt

my directory structure can be seen at

http://www.aliboom.com/dirStructure.txt

Share this post


Link to post
Share on other sites

The problem is that you made symlink to *.so libs.

*.so (same as *.dll on windows) is a "code library".

Your code (program) after compilation should be linked, that means that linker should take *.so (*.dll) and insert into your program some code which will locate functions within shared libraries. This is done with tool xlib.

Steps to link:

0) drop symlinks from ./lib

1) xlib /implib  libatk-1.0.so.0.1213.0.lib /usr/lib/libatk-1.0.so.0.1213.0

1a) ...same for other files

2) copy/move created *.lib to ./lib

(that files needed to link your compiled files - *.o to concrete file)

3) try to build again.

Well, it works on Windows.

As far as I know, it must work on Linux.

Share this post


Link to post
Share on other sites

hmmm ok.  Well, I have no knowledge of any application called xlib (though of course I'm familiar with Xlib in the sense of the libraries), but I'll do some searching and see what I come up with.  Thanks for the help so far.

Share this post


Link to post
Share on other sites

lUm, yeah, but is it part of the Linux package?  I notice in the description of the Windows version it says it includes a:

Library files (.lib) manager

The Linux description doesn't have anything equivalent. - all I seem to have are the actual Xlib libraries. 

I'll keep looking though

Share this post


Link to post
Share on other sites

I had a wee look at this by running "xc =gen Hello.prj" and then modifying the Makefile appropriately.  My findings follow.

The libraries (under SuSE 9.3) are in [tt]/opt/gnome/lib[/tt]. The relevant command from the makefile follows.

gcc -L/opt/gnome/lib  -o Hello Hello.o atk.o gdk2.o gdk2pixbuf.o glib2.o gtk2.o pango.o \ 
         /home/stuff/opt/xds-2.51/lib/x86/libts.a /home/stuff/opt/xds-2.51/lib/x86/libxds.a  -lm \
         -lncurses -lgtk -lgdk -lpango-1.0 -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -latk-1.0 \
        -lgdk_pixbuf-2.0 -lgnomeprintui-2-2

However, I cannot seem to find the following functions (invoked from gtk2.mod).

gtk_file_chooser_default_get_type

gtk_file_chooser_embed_get_type

gtk_file_chooser_entry_get_type

A few mad searches using nm and grep turned up nothing.  Perhaps Dimych can tell us the library where they are found.

Share this post


Link to post
Share on other sites

I don't even get that. My libraries are in /usr/lib

I modified Hello.prj to call them directly, to see if it would help, but it didn't.

Share this post


Link to post
Share on other sites

However, I cannot seem to find the following functions (invoked from gtk2.mod).

gtk_file_chooser_default_get_type

gtk_file_chooser_embed_get_type

gtk_file_chooser_entry_get_type

A few mad searches using nm and grep turned up nothing.  Perhaps Dimych can tell us the library where they are found.

This functions are exist in gtk2.def, but they have underscore prefix (i.e. _gtk_file_chooser_default_get_type).

It was so in source *.inc file (and I don't know why).

Moreover, this functions (like many other) are declared as part of GTK+ 2.4 and higher.

Possibly I've lost some conditional defines - I'll review the library.

Share this post


Link to post
Share on other sites

For convenience, you may copy the xc.tem file and modify it to include the extra libraries, then specify the modified file in the -template equation in your prj file.

...
  !if (env_target="x86linux") then
    ! "\tgcc $(LFLAGS) -o $(TARGET) $(OBJ) $(XLIBS) $(TSLIBS) $(XDSLIB) $(XMACLIBS) -lm -lncurses\n"
  !elsif (env_target="linux") or (env_target="aix") then
...

Just add [tt]" -lgtk"[/tt], [tt]" -lgdk"[/tt], etc. after [tt]"-lncurses"[/tt].

Share this post


Link to post
Share on other sites

[...]

It was so in source *.inc file (and I don't know why).

Moreover, this functions (like many other) are declared as part of GTK+ 2.4 and higher.

Ahh -- that may explain it.  I have only GTK+ 2.0 on my system.  ( I searched my entire gnome tree with "find /opt/gnome/include/ -name '*.h' |xargs grep gtk_file_chooser_default_get_type" and nothing came up.)

Share this post


Link to post
Share on other sites

Actually, I have nothing to say, I just want to see a thread with a "Very Hot Topic (More than 25 Replies)" icon on the Modula-2/Oberon part of the board  :P

Share this post


Link to post
Share on other sites

Does anyone know, what does it means:

I've called "h2d header.h" where header.h is a C header file,

I've got message "All files are up to date" and no *.def files produced.

What should I do?

Share this post


Link to post
Share on other sites

[...]

It was so in source *.inc file (and I don't know why).

Moreover, this functions (like many other) are declared as part of GTK+ 2.4 and higher.

Ahh -- that may explain it.  I have only GTK+ 2.0 on my system.  ( I searched my entire gnome tree with "find /opt/gnome/include/ -name '*.h' |xargs grep gtk_file_chooser_default_get_type" and nothing came up.)

Well, I just did a grep of ./usr lib and on my system, it looks like [tt]gtk_file_chooser_default_get_type[/tt] comes from [tt]libgtk-x11-2.0[/tt] (same with [tt]gtk_file_chooser_embed_get_type[/tt] and [tt]gtk_file_chooser_entry_get_type[/tt])

Share this post


Link to post
Share on other sites

So, just to clarify, this is what I'm getting at the moment (manually breaking the lines here for ease of reading):

Running xc =p Hello.prj gives this:

terry@dorsai:~/xds-gtk2$ xc =p Hello.prj
O2/M2 development system v2.51 TS (c) 1999-2003 Excelsior, LLC. (build 10.05.2005)
Make project "Hello.prj"
#project is up to date
gcc  -o Hello obj/Hello.o obj/atk.o obj/gdk2.o obj/gdk2pixbuf.o obj/glib2.o obj/gtk2.o obj/pango.o  \
/usr/local/xds/lib/x86/libts.a /usr/local/xds/lib/x86/libxds.a  -lm -lncurses -lgtk -lgtk-x11-2.0 -lgdk \
-lgdk-x11-2.0 -lpango-1.0 -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -latk-1.0 -lgdk_pixbuf-2.0 
obj/gtk2.o: In function `GTK_TYPE_FILE_CHOOSER_DEFAULT':
src/gtk2.mod:8691: undefined reference to `_gtk_file_chooser_default_get_type'
obj/gtk2.o: In function `GTK_TYPE_FILE_CHOOSER_EMBED':
src/gtk2.mod:8711: undefined reference to `_gtk_file_chooser_embed_get_type'
obj/gtk2.o: In function `GTK_TYPE_FILE_CHOOSER_ENTRY':
src/gtk2.mod:8734: undefined reference to `_gtk_file_chooser_entry_get_type'
collect2: ld returned 1 exit status
make: *** [Hello] Error 1
external command fault 2:
make -f tmp.mkf

This is my xc-gtk2.tem file:

!set link = "make -f %s", mkfname#mkfext
! "M\t= %s\n",mkfname#>mkfext

!if defined topspeed then
  ! "TSLIBS\t= %s\n","libts"#libext
!else
  ! "TSLIBS\t= \n"
!end

!if defined include_place then
  ! "INCL\t= %s\n", include_place
!else
  ! "INCL\t= .\n"
!end

!if not genlib then
  ! "XDSLIB\t= %s\n","libxds"#libext
!end

!if xmapp then
  ! "XLIBS\t= -L/usr/X11R6/lib -lXm -lXt -lX11\n"
  !if (env_target="x86linux") then
    ! "XMACLIBS\t= %s %s\n","libmac_X11"#libext,"libmac_Xm"#libext
  !end
!elsif xapp then
  ! "XLIBS\t= -L/usr/X11R6/lib -lX11\n"
  !if (env_target="x86linux") then
    ! "XMACLIBS\t= %s\n","libmac_X11"#libext
  !end
!end

!if genlib then
  !if defined libname and (libname#"") then
    ! "TARGET\t= %s\n",libname#>libext
  !elsif defined project and (project#"") then
    ! "TARGET\t= %s\n",project#>exeext
  !else
    ! "TARGET\t= %s\n","libhello"#>libext
  !end
!else
  !if defined exename and (exename#"") then
    ! "TARGET\t= %s\n",exename#>exeext
  !elsif defined project and (project#"") then
    ! "TARGET\t= %s\n",project#>exeext
  !else
    ! { main : "TARGET\t= %s\n",#>exeext }
  !end
!end

!if not defined usestaticclibs then
  !new usestaticclibs-
!end

!if defined ccomp then
!elsif env_target="free_bsd" then
  ! "CDEFS\t= -D_unix -D_free_bsd -DX2C_no_spawn -DX2C_strcmp\n"
  ! "CF\t= -O2 -c -I$(INCL)\n"
  ! "CC\t= cc\n"
  !new ccomp = $$(CC) $$(CDEFS) $$(CF) -o %s %s
!elsif (env_target="linux") or (env_target="x86linux") then
  ! "CDEFS\t= -D_unix -D_linux -DX2C_no_spawn -DX2C_strcmp\n"
  ! "CF\t= -O2 -g -I$(INCL) -c\n"
  ! "CC\t= gcc\n"
  !if defined linuxaout_support and linuxaout_support then
  !  "OBJFF\t= -bi486-linuxaout\n"
  !else
  !  "OBJFF\t=\n"
  !end
  !if usestaticclibs then
    ! "LFLAGS\t= -static\n"
  ! else
    ! "LFLAGS\t=\n"
  !end
  !new ccomp = $$(CC) $$(OBJFF) $$(CDEFS) $$(CF) -o %s %s
!end

!if defined asmcomp then
!elsif (env_target="x86linux") or (env_target="linux") then
  !new asmcomp = as -o %s %s
!end

# ------------------ objects enumeration ------------------
#                    -------------------

! "OBJ="; { obj : " \\\n\t%s",# }

# ------------------- target make rules -------------------
#                     -----------------

!if genlib then
    ! "$(TARGET) : $(M) $(OBJ)\n"
    !if (env_target="linux") or (env_target="x86linux") or (env_target="free_bsd") or (env_target="sunos4") or \
(env_target="aix") then
      ! "\trm -f $(TARGET)\n"
      ! "\tar q $(TARGET) $(OBJ)\n"
      ! "\tranlib $(TARGET)\n"
    !else
      ! "\tar q $(TARGET) $(OBJ)\n"
    !end
!else
  ! "$(TARGET) : $(OBJ) $(XDSLIB)\n"
  !if (env_target="x86linux") then
    ! "\tgcc $(LFLAGS) -o $(TARGET) $(OBJ) $(XLIBS) $(TSLIBS) $(XDSLIB) $(XMACLIBS) -lm -lncurses -lgtk  \
-lgtk-x11-2.0 -lgdk -lgdk-x11-2.0 -lpango-1.0 -lglib-2.0 -lgmodule-2.0 -lgobject-2.0 -latk-1.0 -lgdk_pixbuf-2.0 \n"
  !elsif (env_target="linux") or (env_target="aix") then
    ! "\tgcc $(LFLAGS) -o $(TARGET) $(OBJFF) $(OBJ) $(XLIBS) $(XDSLIB) -lm\n"
  !else
    ! "\tcc $(LFLAGS) -o $(TARGET) $(OBJ) $(XLIBS) $(XDSLIB) -lm\n"
  !end
!end

# ----------------- Dependency information ----------------
#                   ----------------------

! { asm : "%-12s : $(M)",#>objext; " %s\n\t",#asmext; asmcomp,#>objext,#asmext; "\n\n" }
! { c : { header : "%-24s : %s\n",^#>objext,#header } \
  "%-24s : $(M) %s\n\t",#>objext,#; ccomp,#>objext,#; "\n\n" }

# end of makefile

And this is my Hello.prj file (results are the same with .so):

-O2+
-lookup = *.sym = .
-lookup = *.def = .
-lookup = *.mod = .
-lookup = *.obj = .
-lookup = *.lib = /usr/lib
-template = xc-gtk2.tem
!module ./Hello.mod
!module /usr/lib/libglib-2.0.la
!module /usr/lib/libgmodule-2.0.la
!module /usr/lib/libgobject-2.0.la
!module /usr/lib/libatk-1.0.la
!module /usr/lib/libpango-1.0.la
!module /usr/lib/libgdk_pixbuf-2.0.la
!module /usr/lib/libgdk.la
!module /usr/lib/libgtk.la
!module /usr/lib/libgtk-x11-2.0.la

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×