I previously reported (to the glasgow-haskell-bugs mailing list)
problems installing Greencard for Hugs.
I have now solved those problems, and have a working interface
from Hugs to mSQL (a simple SQL-based database client/server system).
(I'm posting this to the Hugs users list as well, to encourage other
Hugs users to develop Greencard interfaces.)
Here are the steps that I had to follow to get Greencard working with Hugs
(under Linux i386). Please include some of these comments in the greencard
installation guide etc. if you think they will help other Hugs-Greencard
users.
* install ghc! (it was not obvious at all to me that I had
to do this. But, perhaps I would not have to if
the "binary bundles" on the Greencard web page
were available? Anyway, I think the documentation
should say that you need ghc to build greencard).
* make greencard (using ghc)
1. In greencard's top-level Makefile, I set FOR_SYSTEM=hugs
and set HC to point to ghc, as the INSTALL instructions said.
2. Then do 'make'
3. link/copy ./src/green-card into /usr/local/bin (or similar)
4. In ./lib/hugs, the Makefile says that it is incomplete.
So, add the following rule to it
(and add StdDIS.so into the 'all' target):
StdDIS.so: StdDIS.c
gcc -shared -o StdDIS.so -I /usr/local/hugs/src StdDIS.c
5. Also, in ./lib/hugs, StdDIS.gc exports mkForeignObj but
does not define it. Remove this from the export list.
(This seems to be a bug in StdDIS.gc ? )
6. Do 'make' in ./lib/hugs.
* set my own Makefile up with the correct include and library paths.
For example, I ran greencard as:
green-card --target hugs --include-dir $(GCHOME)/lib/hugs MSQL.gc
and to compile the generated .c files (say MSQL.c), I used:
gcc -shared -o MSQL.so -I /usr/local/hugs/src MSQL.c
Just for everyone's entertainment, here is a simple example
program that uses Hugs-mSQL, and the output that it produces.
----------------------------------------------------------------------
-- This takes an SQL 'where' expression (we) and displays the
-- first_names it produces. It uses the emp_details relation
-- in the 'testdb' database, on the local server.
query :: String -> IO ()
query we
= do sock <- msqlConnect ""
msqlSelectDB sock "testdb"
n <- msqlQuery sock ("select first_name from emp_details where " ++ we)
putStrLn (show n ++ " rows returned.")
res <- msqlStoreResult
-- we could find out how many columns were returned (1 in fact),
-- but I will output more to show how robust msqlData is.
putStrLn (unlines [show [msqlData res r c | c <- [0..4]]
| r <- [0..n-1]])
----------------------------------------------------------------------
TestMSQL> query "emp_id > 500"
["David","","","",""]
["Mark","","","",""]
----------------------------------------------------------------------
I must say that in spite of these teething problems, I am
*very* impressed with Greencard. I am now confident that I
can go away and interface Hugs to my coffee-maker, my MIDI
keyboard and anything else that takes my fancy. Hopefully
my students will enjoy the resulting capabilities of Hugs too!
Thanks!
Mark.
Dr Mark Utting, Senior Lecturer
Department of Computer Science
School of Computing and Mathematical Sciences
The University of Waikato Tel: +64 7 838 4791
Private Bag 3105 Fax: +64 7 838 4155
Hamilton Email: [EMAIL PROTECTED]
New Zealand Web: http://www.cs.waikato.ac.nz/~marku
The highest bandwidth output from a human is the notes pouring
from a concert pianist's fingers.