Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!pacbell.com!ames!ucsd!hub.ucsb.edu!fir!murat From: murat@fir.ucsb.edu (Karaorman, Murat) Newsgroups: comp.lang.eiffel Subject: Re: C and Eiffel ? Message-ID: <12051@hub.ucsb.edu> Date: 12 Jun 91 21:34:16 GMT References: <702@mailgzrz.tu-berlin.de> Sender: news@hub.ucsb.edu Reply-To: murat@cs.ucsb.edu (Murat Karaorman) Organization: University of California, Santa Barbara Lines: 98 In article <702@mailgzrz.tu-berlin.de> duns1222@w203zrz.zrz.tu-berlin.de (Martin Dunschen) writes: >Hello, > >We have a problem calling eiffel from C. > >We typed in the example as given in "Eiffel: The Language" Version 2.2, page >221 (but we use version 2.3 level 4) and tried to create an executable >programm by adding an appropriate (?) "main.c". Of course we got errors That part of the documentation IS faulty, as I remember having bumped into about one and a half years ago >from "ld" saying, that there are undefined symbols. Okay, so we hacked in >a toy class calling this given example. Compiled with "es" everything works >fine. Now we want to use this in conjunction with eiffel classes compiled to C. >To get these C-versions of the system's classes we generated a C-package by >changing the SDF. > >Is this necessary, or is there another way to use the C verions of the >system classes? > >We ran "identify A" in the directory containing the C-routines. >An archive was created. > >But what now? When we try to link everything together with a self written main >"ld" complains about undefined symbols (eif_create, eif_rout, eif_attr, >MakeStr), which we found in the archive-file in __eifc.o (most of them)! > >To complete the confusion we add the sources of everything as a shell-archive. >Please try it and tell us, what we do wrong. [... stuff deleted for brevity ...] What you need to do is basicly the following: 1) create a C-package archive (using the standard identify, etc. stuff) and make it visible under a name you choose (do VISIBLE (Y): my_name during C-package generation). This should create a my_name.a file. 2) write your C program that creates eiffel objects, sends them messages etc., this is similiar to the sample prgm in the documentation, EXCEPT before doing anything you need to start-up an associated eiffel runtime environment by calling my_name_eiffel_init(); before using any eiffel objects. 2.1) In this C program you shouldn't use eif_rout ( ... ) to invoke a method, but instead obtain a function pointer to the method and then invoke the method via this pointer. You can look at the example I give. 3) compile this C program, say test.c, using cc -o test test.c my_name.a provided that you have the correct paths, etc. 4) (hopefully) test is runnable. 5) You don't need to create the C-package again as long as your C programs requirements for the Eiffel environment don't change. 6) Below is how I would modify your test.c code that follows my guidelines. The lines starting with >> are my insertions, The lines starting with << were in your original, they need to be removed, The rest is unchanged (except for inserting DATUM) from your original. ==============================test.c======================================= #include "/cad01/Eiffel/files/_eiffel.h" #include >> #include " ... rename.h " >> #include " ... Eiffel_rout.h" extern OBJPTR eif_create (); extern DATUM eif_rout(); extern int eif_attr (); << int test () >> main () { OBJPTR obj; >> ROUT_PTR f_ptr; >> my_name_eiffel_init(); obj = eif_create("string",(DATUM) 10); >> f_ptr = eif_rout (obj, "append"); >> (* f_ptr)(obj, MakeStr("Hello world")); << eif_rout(obj, "append", MakeStr("Hello world")); printf("Size of Eiffel string is: %d\n",(int32) eif_attr (obj, "size")); return 25; } =================================end==================================== I hope this helps. Let me know if anything goes wrong. It has been a while now, but I know that this stuff should eventually work. good luck, -----------------------------------------------------------------------------. | Two men say they're Jesus... | | One of them must be wrong. | | -Dire Straits "Industrial Disease" from Love Over Gold |